|
|
|
|
|
by whilenot-dev
673 days ago
|
|
I disagree. People are sometimes just forced to think imperatively when dealing with computers, but I usually think declarative when I design my programs. Say if I want to filter a sequence of users and omit users below the age of 18, I'll construct my predicate (a "what"), and want to apply that predicate to create a new sequence of user (another "what"). I really don't want to tell a computer how to process a list every single time. I don't care about creating an index first and checking the length of my list in order to keep track that I process each user in my list sequentially, and don't forget that important "i++". All I want at that moment is to think in streams, and this stream processing can happen in parallel just as well for all I care. But I also do think Python, Haskell etc. are the most expressive here with list comprehensions. It can't get more concise than this IMHO: users_adult = [
user
for user in users
if user.age >= 18
]
|
|