4 ms·
Are you saying you find Array.map(e => f(e)) Easier to read than for(e in Array) { f(e) } I don’t see how they really are any more or le
by edgyquant 5y ago
Are you saying you find
Array.map(e => f(e))
Easier to read than
for(e in Array) {
f(e)
}
I don’t see how they really are any more or less readable, although I’ll admit map gave me a day of rethinking when I switched from 100% python to using react on the frontend.
- lkschubert8 5y agoI think Array.forEach(...) is the more apt analog there as it wouldn't be generating a new array of the return like map would.
- edgyquant 5y agoMaybe, I only went with map since it was in the GP.
- hnedeotes 5y agoTechnically you would use Array.forEach(e => f(e)) If you don't care about transformations. Which is basically the same as your for Map is when you want to return a new collection with each original item in it mapped to a "different" thing.
- brundolf 5y agoforEach is an outlier, because most of these methods transform something into something else and can be chained, and that's where the readability increase comes in. I usually prefer for loops over forEach because it emphasizes the fact that forEach doesn't return a value; it's used purely for the sake of side-effects.
- pwdisswordfish0 5y agoProgramming punditry makes a lot more sense if, when you see someone talking about the code being more readable, you understand that most of them are lying to themselves about what they really mean. Which is code that is more writable. In other words, something that's easier for them, the lazy person who is punching keys and derping around in a text editor.