News for hackers. Stuff that matters.
Re:Ruby 3.2.0 Is from Another Dimension by empthought on Wednesday January 04, 2023 @07:24AM (#34244729)
> I think the Ruby solution is more readable.

I disagree and I’ve used both professionally for about the same amount of code.

Re:Ruby 3.2.0 Is from Another Dimension by nickjj on Wednesday January 04, 2023 @08:56AM (#34245515)
I think this is purely a personal preference but I also think there is a bias towards list comprehensions being more difficult to mentally parse.

I do a lot of contract work and chatted with a ton of folks ranging from beginners to veterans. A lot of them (well more than half) avoid list compressions, especially when working with teams because it's such a mixed bag of either being able to instantly understand them or it requires more effort. Personally I don't use them in my code (for both reasons).

Both Ruby solutions are much more clear to me even though I have no functional programming background. I have no preference towards functional styles either, I would say it's the opposite. I struggled with Elixir long enough that I stopped using it.

Re:Ruby 3.2.0 Is from Another Dimension by empthought on Wednesday January 04, 2023 @11:40AM (#34247820)
I disagree about list comprehensions, as do more than half the people I’ve asked over the years.
Re:Ruby 3.2.0 Is from Another Dimension by eternalban on Wednesday January 04, 2023 @09:19AM (#34245737)
I don’t use either, and also have an admittedly irrational dislike for Python. That said, the Python variant is more readable imo as well.
Re:Ruby 3.2.0 Is from Another Dimension by michaelteter on Wednesday January 04, 2023 @01:50PM (#34249723)
And yet, in the production Python codebases I've worked with, list comprehensions are rarely seen. Usually it's typical loop iterations. I wonder why that is?...
Re:Ruby 3.2.0 Is from Another Dimension by empthought on Thursday January 05, 2023 @01:12PM (#34263990)
This says much more about you and the developers and codebases you work with than anything to do with Python list comprehensions.

Coming from a point of zero knowledge of the codebase, I picked Flask. I picked the cli.py module in Flask. And what do I find?

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

https://github.com/pallets/flask/blob/main/src/flask/cli.py#...

The keyword "for" occurs twice as often in comprehensions and generator expressions as it does in "typical loop iterations!"