How much sugar do classes need?

Peter Michaux petermichaux at gmail.com
Mon Nov 24 20:45:08 PST 2008


On Mon, Nov 24, 2008 at 7:37 AM, P T Withington <ptw at pobox.com> wrote:
> On 2008-11-22, at 23:54EST, Peter Michaux wrote:
>
>>>
>>>       let privClassVar = 1;
>>>       const privClassConst = -1;
>>
>> So members are private by default? I like that and it is consistent
>> with a style of JavaScript OOP popular today. In the wiki page members
>> are public by default which is as dangerous as implied globals (i.e. a
>> missing "var") in ES3.
>
> My 2p:  I feel just the opposite.  Conflating classes (OOP) with access
> control is a big mistake in my book, a big mistake made by Java that we
> ought to learn from. It leads you to either write really huge classes, or
> to have to 'decorate' all your classes with public declarations.

Why do private members cause "really huge classes"?

> Access
> control should have its own orthogonal mechanism -- modules or packages that
> can consist of one or more classes and can gather the access control
> declarations in one spot so they are easily analyzed, as opposed to
> scattering them over all the component classes.

If access control for a class member was not written with that class
member, then it would mean a lot of hunting around the code to
determine if a member is public or private. That seems like a recipe
for trouble to me. It reminds me of some aspect oriented programming
where hunting and gathering is necessary to determine if a filter is
being applied to a particular method or not. That is a lot of hard
work and something I've worked to avoid at all costs.

Peter


More information about the Es-discuss mailing list