▲ | creata 8 hours ago | |||||||
The Ruby syntax doesn't seem that different to many other languages. For example:
Python seems to be the odd one out. Imo, its list comprehensions are confusing as hell to "newcomers". For example, when a list comprehension has multiple `for`s, what order are they nested in? | ||||||||
▲ | quietbritishjim 3 hours ago | parent | next [-] | |||||||
> ... confusing as hell to "newcomers". For example, when a list comprehension has multiple `for`s, what order are they nested in? I get that this is just a rhetorical question to make a point about newcomers, and I do agree it's not immediately obvious, but for the record: you can imagine any "if"s and "for"s in a list comprehension are nested statements in the same order. So, for example, this:
Is equivalent to this:
So the least comprehension is basically in left to right order with the one exception of the actual expression to be added to the list (like y.foo() in the example above). | ||||||||
| ||||||||
▲ | abenga 7 hours ago | parent | prev [-] | |||||||
Those both seem a little bit more consistent than the Ruby example, however. To understand the JS example for example, you only need know that to call a method on an object, you do `object.method(arguments)`, and this is chained in a straightforward manner, with methods called on the returned values left to right. Ditto for the Haskell example. Maybe the Ruby one does the same thing, but even in this extremely simple example, we still have two different ways of doing the same thing. For Python, you don't really have to use list comprehensions in the place of multiple for loops, you can sacrifice the brevity afforded to write the same thing in a more easily understandable fashion. |