News for hackers. Stuff that matters.
Re:Good Refactoring vs. Bad Refactoring by The_Colonel on Tuesday August 20, 2024 @01:42AM (#41297136)
> Even for more experienced programmers, reading imperative probably cost less energy, since it is more internalised?

I disagree. For-cycles are usually more difficult to reason about, because they're more general and powerful. If I see "for (...", I only know that the subsequent code will iterate, but the actual meaning has to be inferred from the content.

Meanwhile, a .map() or .filter() already give me hints - the lambda will transform the values (map), will filter values (filter), these hints make it easier to understand the logic because you already understand what the lambda is meant to do.

Other benefits stem from idiomatic usage of these constructs. It's normal to mix different things into one for-cycle - e.g. filtering, transformation, adding to the resulting collection are all in the same block of code. In the functional approach, different "stages" of the processing are isolated into smaller chunks which are easier to reason about.

Another thing is that immutable data structures are quite natural with functional programming and they are a major simplification when thinking about the program state. A given variable has only one immutable state (in the current execution) as opposed to being changed 1000 times over the course of the for-loop.

Re:Good Refactoring vs. Bad Refactoring by math_dandy on Tuesday August 20, 2024 @06:28AM (#41298645)
No need to fear mutable local state. Shared state is where immutable data structures really shine.
Re:Good Refactoring vs. Bad Refactoring by persnickety on Tuesday August 20, 2024 @04:46PM (#41303879)
> If I see "for (...", I only know that the subsequent code will iterate

And then someone slaps do {} while(0) in a macro.