Comment

Comment by timtas

The reason to prefer reduce over for or while loops is because procedural loops mutate state defined in higher scopes in the program, making reasoning harder and introducing all kinds of opportunities for tricky bugs.

I like reduce, and I’ve never gotten pushback for using it. I’d be willing to use other functional method chains. But I would never listen to anyone who suggested using a procedural loop instead.

parent timtas 1 month ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton