News for hackers. Stuff that matters.
Re:JavaScript at 20 by nilliams on Friday May 15, 2015 @07:27PM (#9554291)
> You don't need the backslash on the first, making it a little cleaner

I was not trying to illustrate that the backslash made it ugly (I've removed it - I was pasting from a repl). It's ugly because of Python's lambda syntax and the fact it does not compose 'sensibly', as compared to fluid interfaces. The logic is back-to-front for one.

> But the list comprehension version is just completely wrong:

No, it's not at all wrong. Your one-liner is not better and (I hope) would probably upset most teams for being less clear.

I was providing a like-for-like example. The multi-lining is not the criticism of the Python version. It's the composition that's at fault, the fact it does not feel like 'two coherent operations over a list' with two distinct conditionals.

The ES5/ES6 examples demonstrate this much more clearly IMO.

Re:JavaScript at 20 by 59nadir on Saturday May 16, 2015 @01:32PM (#9556911)
What you're saying, then, is that it's terribly confusing [for you] when someone uses a list comprehension fully?

Presumably, these also are not completely clear to you:

    > [x * 2 | x <- [1, 2, 3, 4], even x]
    [4,8]
    > [x * 2 | x <- filter even [1, 2, 3, 4]]
    [4,8]
What, exactly, is not clear here? This is the essence of composition; to use clearly defined things together. I can appreciate a good pipeline as much as the next guy, but to say that this is somehow more complicated and hard to read is to overstretch a little bit.

To say that a pretty uncluttered list comprehension is some challenge to read is just hyperbolic. These pipelines, even with newlines, can get pretty long and terrible too.