Hacker News new | ask | show | jobs
by angusgr 5653 days ago
> I want my code to say what I mean, not just evaluate to what I mean.

This is an awesome rule of thumb. A more succinct version of Knuth's "Programs are meant to be read by humans and only incidentally for computers to execute"

> the first makes my intent clearer than the second:

I really think the beauty of list comprehensions may be in the eye of the beholder.

I personally find the list comprehension syntax easier to read than equivalent map syntax most of the time, especially (as you point out) for cases where you want an anonymous function (ie quite often), but even for simple ones like your example.

Doubly so when you start chaining map & filter functionality to do one thing. Statements like [ f(x) for x in xs if g(x) > 3 ] seem to read quite nicely for me. You only need to change two words and you have a pseudocode description: "f(x) for all x in xs where g(x) > 3".

This is obviously subjective, though, and maybe I'm in the minority. I knew list comprehensions before I knew Python, so I'll accept that makes me suspect.

(Edited for clarity)