Le 07/05/2011 02:04, Peter Michaux a écrit :
> I'd like to ask when is "function" too long? I never type it thanks to
> my text editor's features so I know it is not too long for developers
> with a good editor.
What editor are you using? I have always been disappointed in my
experience with IDEs and JavaScript integration and would be glad to
know what people use for JavaScript (I'm actually asking the question to
everyone).

I'm attracted to the idea of a shorter function syntax not only because
it reduces the number of characters of the "function" keyword, but also
because it gets rid of the "return" keyword (and corresponding semicolon).
The particular case where I would enjoy shorter syntax is when using
inlined functions in array extras.
----
// assuming a is an array
a.filter( (e)->(typeof e === "number" && e>3) )
 .map( (e)->(e*e) )
 .reduce( (prev, curr)->(prev+curr), 0);
----
This is obviously extremely subjective, I admit. And there is no right
or wrong answer/opinion, it's really a matter of taste.
I actually prefer the idea of the # notation, because it looks "more"
like a function with its brackets ("{" and "}") while in my example,
without any help of syntax highlighting, the reader can easily get lost
in nested parenthesis. Same example with #:
----
// assuming a is an array
a.filter( #(e){typeof e === "number" && e>3} )
 .map( #(e){e*e} )
 .reduce( #(prev, curr){prev+curr}, 0);
----
This looks more clear to me. But once again, this is very subjective.


Your message seems to assume that the choice of providing a shorter
syntax is to help JS code writer. I have the opposite opinion: a shorter
syntax should be introduced to help code readers.
In most cases I have seen for array extras functions, the function has
only one return statement. While reading the code, having the function
inlined avoids to look for the function in some other place in the code
and getting rid of a dozen character makes the line shorter without
introducing ambiguity.

My two cents,

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

Reply via email to