I used to write a lot of JavaScript like this:
const result = users .filter(user => user.active) .map(user => user.name) .sort() .slice(0, 5);
Nothing here is wrong. I wrote code like this all the time. But this is exactly the kind of thing that feels fine at first, then slowly gets harder to work with.
Chaining is great…until it isn’t
The issue isn’t .map() or .filter() . It’s what happens when you stack them. You stop writing steps and start writing pipelines.
Pipelines look clean, but you still have to walk through them in your head: filter → map → sort → slice.
That’s fine once or twice. Do it all over a file and it starts to wear on you.
Compare that to this:
const activeUsers = users.filter(user => user.active); const names = activeUsers.map(user => user.name); names.sort(); return names.slice(0, 5);
Yeah, it’s more lines. But each step is just sitting there. No decoding required.
... continue reading