On Mon, May 9, 2011 at 10:40, Kyle Simpson <get...@gmail.com> wrote:

[snip]

> One thing that troubles me about the goal/movement to have a shorter
> "function" syntax... It seems like all the examples we exchange for it are,
> on principle, single-line functions. From a readability standpoint, I think
> it's a little deceptive to judge a syntax like that, without considering how
> it will look for a longer, non-trivial function. How easy will it be to scan
> for a function's start/end if the biggest visual signal for a function start
> (aka, "function") is gone and is replaced by that rather non-descript ->
> which, as was said earlier in a thread, looks a lot like existing operators.
>
> Since in the real world, functions are usually a lot more than a single
> return statement or a single assignment, I think we should at least keep in
> mind the readability (or lack thereof) of how these proposals look when
> there's 10, 20, 100 lines in a function... By the same token, how easy is
> the readability when there's 2-4 levels of nested functions (the module
> pattern, etc)?

Since several people have asked about and for feedback from the
greater developer community and since I don't think there's a way to
resolve these questions quantitatively, here's my two cents:

The main problem I'm having with declaring lambdas inline is the sheer
verbosity of it. That is, I don't care about _writing_ the code so
much as _reading_ it and stumbling upon it each and every time. You
(Kyle) say that you fear for your code's readability when a shorter
syntax is used for very long functions. I have exactly the opposite
problem: Because of the verbosity required to express even the
(otherwise) most concise statements, I declare my lambdas and then use
their name to increase readability most of the time. While I agree
that there are lots of cases where it's desirable to immediately see
the function start, there's also lots of cases where I'd want the
function itself to be nearly invisible so as to be able to focus on
the contained functionality as much as possible.

Thus, I'd much rather read
var onlyOdds = myArray.map(#(item) {item % 2});
or
var onlyOdds = myArray.map((item) -> (item % 2));
than
var onlyOdds = myArray.map(function(item) {return item % 2});

(I'd love
var onlyOdds = myArray.map(item % 0);
but since that's not going to work, I'm willing to settle for the
next-best thing)

To be honest, I don't really care about which exact syntax gets
chosen. I guess if I could freely choose, I'd go for #, but I
understand the desire to save that symbol for other usages. Also, "->"
communicates intent very nicely in many cases, I think.
>
>
> --Kyle


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

Reply via email to