How much sugar do classes need?

Mark S. Miller erights at google.com
Sun Nov 23 07:24:11 PST 2008


On Sat, Nov 22, 2008 at 8:54 PM, Peter Michaux <petermichaux at gmail.com>wrote:

> 2008/11/22 Mark S. Miller <erights at google.com>:
>
> >         Point.pubClassConst = -3;
>
> Why not the following?
>
>  public pubClassConst = -3
>

I'm glad you raised this first. This example is a good microcosm of the
issues distinguishing the two sugar proposal. My reasons for preferring the
first:

* The second form desugars to the first, but is no more convenient than the
first. So introducing sugar here is not justified on convenience grounds.

* The second form obscures the difference between variables and properties,
which does the ES programmer no favors. In ES, "instance private" means
lexically captured variable. ES has no other encapsulation mechanism, and
the essence of the classes-as-sugar proposal is to employ that mechanism to
create encapsulated instances. "Public" means exactly string-named property.
(A third category, class-private instance variables, depends on the
introduction of Name objects, which both Cormac and I have left out of our
first examples.)

As for "familiarity to Java programmers", more people learn ES as their
first language that Java. Java programmers have already learned to program.
Making things easier for Java programmers to learn, at the price of making
it harder for new programmers and for ES3 programmers (as well as functional
programmers) seems like a bad tradeoff. ES already won where Java lost.
There's no reason for us to imitate its mistakes.

It probably makes sense to argue through this one example first, as most of
the rest of the differences between the sugar proposals have these same
motivations.

-- 
   Cheers,
   --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20081123/1905ed35/attachment.html>


More information about the Es-discuss mailing list