News for hackers. Stuff that matters.
Re:PEP 308 and why I still hate Python by djsumdog on Thursday March 09, 2017 @09:08PM (#13835753)
Yea, I like list comprehensions. I mean they make sense once you're use to reading the syntax. That's just like the following in Scala:

   foo = baz.list().filter{ bar => condition(bar) }.map(transform(_)).toList
If it's your first time looking at Scala, you'd probably be like, "What the fuck is that shit?" but as you learn the language, these types of patterns become common and make a lot of sense.

I mean it's not like weird rules in natural language. At least the grammars for computer languages are strict, with very few edge cases (compared to human/spoken language).

Re:PEP 308 and why I still hate Python by p4lindromica on Thursday March 09, 2017 @09:42PM (#13835895)
I hope you mean:

    foo = baz.list().filter(condition).map(transform).toList
No need to create the extra anonymous functions.
Re:PEP 308 and why I still hate Python by nerdponx on Thursday March 09, 2017 @09:44PM (#13835906)
Does Scala have line continuation? I got really used to pipes from R (which I guess come from F#/Elixir), which in turn got me really comfortable with multi-line statements like:

    foo = baz.\
        list().\
        filter{ bar => condition(bar) }.\
        map(transform(_)).\
        toList
IMO this is about as readable as it gets. It's like bullet points enumerating each step in the "algorithm" that produces a `foo`.

AFAIK Javascript also uses this pattern a lot.

Re:PEP 308 and why I still hate Python by uiri on Thursday March 09, 2017 @09:51PM (#13835936)
I think that Scala uses semicolon terminated lines so you would write something like:

    foo = baz
        .list()
        .filter{ bar => condition(bar) }
        .map(transform(_))
        .toList;
Re:PEP 308 and why I still hate Python by djsumdog on Thursday March 09, 2017 @10:57PM (#13836253)
Scala doesn't require the semi-colon at the very end, but it does allow for them if you really want two statements on the same line.

Edit: and yes, that line separation works fine, both compiled and in the REPL.

Re:PEP 308 and why I still hate Python by jfroma on Thursday March 09, 2017 @09:45PM (#13835909)
BTW similar syntax in javascript, ruby, c#, etc.