Just to add my two cents, I would like to let you remember that the arrow syntax should not be viewn as the only way to avoid the 'return' statement and the brackets. "function(x) x*x;" does the trick too, whithout introducing any new keyword. To those that think that the arrow syntax is easier to type because there's less characters to type, it may be disappointing to notice it's not the case : "(x) -> x*x;" is only 5 characters shorter than the other form but :

- You don't beneficiate from autocompletion anymore (in most IDE, typing 'fun+TAB' brings up 'function' arlready)

- The '-' and the '>' characters are more complex to type (on my keyboard, both then - and the > char requires me to move my hand away from its standards position, and the time it takes to type ' -> ' equals or is more important than the time I need to type 'function' in *full* word, which I usually don't need to).

- The syntax is less clear. CSharp originally introduced something like that in the past, and I never liked the syntax. (It's to notice that the VB.NET language later implemented the lambda feature using the "Function(X) X*X" syntax). Okay, if I could really choose, I would prefer the "@(x) x*x;" syntax, which is already implemented "as-is" in other scripting languages such as MatLAB (but I already hear the concerns about other possible usages of the @ sign).

   - It introduces ambiguities in the code (Sample: var z = (x) -> x || y)

Regards,
François


-----Message d'origine----- From: Brendan Eich
Sent: Saturday, May 07, 2011 3:39 AM
To: Peter Michaux
Cc: es-discuss@mozilla.org
Subject: Re: arrow syntax unnecessary and the idea that "function" is too long

On May 6, 2011, at 5:04 PM, Peter Michaux wrote:

The only possible category is "be a better language" but the arrow
syntax won't make JavaScript a better language for complex
applications or libraries in comparison to any other kind of
JavaScript code.

Usability is always on the top three lists of programming language success factors. 'function' and 'return' are too long.


I would argue that the arrow syntax will make
JavaScript a worse language anyway as there are already perfectly good
forms using the "function" keyword now.

Eight characters is at least six too many.


We don't need new syntax and
we don't need multiple ways to do the same thing just for the sake 6

Wrong, 14. You are not counting 'return'.


characters. Please keep JavaScript simple.

Sorry, this is a bogus argument. "Simple" does not mean "fewest productions in all possible grammars" or "fewest ways of saying any given sentence." That is simpler by some measures, more complex by others. In particular, writing and (lesser but still material) reading 'function' over and over is not a win.

Consider the destructuring object shorthand: let {x, y} = pt; instead of let {x:x, y:y} = pt;


Look at all the complex/subtle edge cases mentioned in the wiki page
about arrow function syntax. Do we really want to have that much
trickiness added to the language?

The wiki page is a work in progress. I have updates coming, which should address the parenthesization burden. But again, you can use 14 characters if you want. This is shorthand, and only shorthand. And usability counts, so shorthands are in Harmony (e.g., destructuring)

Gzip is not the issue (although stats I've seen from Steve Souders show too may scripts not being compressed at the Transfer-encoding layer). Human usability is.

/be

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to