Comment by verinus
4 years ago
if you are used to imperative programming, then yes.
But in a for loop anything can happen- from a map to a reduce to a mix, to whatever convoluted logic the dev comes up with.
4 years ago
if you are used to imperative programming, then yes.
But in a for loop anything can happen- from a map to a reduce to a mix, to whatever convoluted logic the dev comes up with.
Technically you can implement map as reduce ;)
But yes - for me
is slightly more readable than
I mean in this case the name kinda makes it obvious anyway :)
If the operation is conceptually accumulating something over the whole collection and if it's idiomatic in the language I'm using - I will use reduce. Same with map-y and filter-y operations.
But if I have to do some mental gymnastics to make the operation fit reduce - for loop it is. Or generator expression in case of python.
Indeed. I rarely encounter basic loops in code reviews now, so seeing one is definitely a small alert to do an extra thorough review of that part.
And it is usually very easy and straightforward to see what is going on inside.