Hacker News new | ask | show | jobs
by KPGv2 73 days ago
>You have to define a free function to keep your fold readable and understandable.

I agree. But you'd do that for a for-loop, too, unless you want a bloated for-loop.

> In for-loop it's much easier to understand.

I have to disagree there. You'd still be working with a free function, or you'd be working with a bloated for-loop body.

Combining cache loopkups, metric tracking, etc. runs into SOC issues that IME for-loops just let imperative developers get away with until it comes time to test their code.

Furthermore, free functions aren't bad. They're good. They're a self-documenting abstraction. Unless you name it `function_one` or something.

Having my fold lambda do its primary business role but call `update_cache_and_metrics` makes it unnecessary for someone reading the flow of logic from even needing to go read the body of that free function.