Is class syntax really necessary ?
david.bruant at labri.fr
Mon May 23 12:12:45 PDT 2011
Le 23/05/2011 20:15, Mikeal Rogers a écrit :
> this is going to get a little philosophical and not super technical so
> i apologize in advance.
> i don't agree that expressiveness is necessarily a good thing.
> expressiveness comes with a cognitive overhead when reading and
> thinking about code, it's in your head, always. the more feature, the
> more language semantics, the more you have to keep in your head before
> you even start adding the lines of code you're keeping in there.
I disagree with you on your generalization:
"a += 1" is more expressive than "a = a+1" and I don't see a cognitive
overhead is the former, maybe the opposite, it helps the reader to
understand more easily understand the writer's intent.
Exact same thing when replacing a for-loop traversing an array with a
.forEach/.map/.filter/etc. call. They are a very good way to be
expressive and show an intent which is easy to understand both from the
interpreter perspective and human reader perspective.
> saving 4 lines of code with new language semantics might save 4 lines,
> but those were 4 lines in one place that i only had to think about in
> that spot. the new expressiveness i have to carry around with me
> whenever i think about any code.
I however agree that adding new syntax just for the sake of saving a
couple of lines isn't a good idea. And I have to admit that so far, I am
not convinced by the benefits of the class syntax in terms of abstraction.
> i don't think it's a win to add semantics to the language that
> accomplish something *we can already do*. there are lots of ES.next
> features that let us do something that we could not do at all
> previously (weak tables and refs are a good example). features that
> enable new kinds of applications we couldn't previous build.
> i said it at NodeConf and I'll say it again here, nobody ever said "i
So far, we're discussing the problem from the JS writers perspective.
But I am more concerned by the consequences of how adding "classes" will
be received by newcomers who come from Java or PHP. Will this syntax
help them to write JS or encourage them to not learn JS fundamentals? I
only have the question, not the answer, unfortunately.
I read a lot of JS code and it's sometimes depressing to see people
writing "new Array()" all over the place and use their "arrays" as a JS
writer would normally use objects. Such code is very likely to be
written by people who come from the PHP world where "array" is the
easiest (string) key -> value language construct. I agree that this
example is harmless, but I am worried that there could be other issues
when people don't learn JS fundamentals.
Moreover, I've been really interested by this presentation  where one
point is that some OO programming languages have two OO concepts (Object
and Class) while some others (including JS) only have one (Object). I'm
worried that adding a class abstraction may lead us to the same issues
noted in the presentation.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss