News for hackers. Stuff that matters.
Re:Bun v0.8.0 by flohofwoe on Thursday August 24, 2023 @02:34AM (#37245717)
This just shows again that readability is entirely subjective, IMHO combinations of .map, .filter, .reduce, etc are often less readable than doing the same thing in a nested loop.
Re:Bun v0.8.0 by vorticalbox on Thursday August 24, 2023 @03:42AM (#37246113)
This is true I code very functional style in javascript but I can see how that might be harder to read for some.
Re:Bun v0.8.0 by e12e on Thursday August 24, 2023 @07:32AM (#37247634)
> combinations of .map, .filter, .reduce, etc are often less readable than doing the same thing in a nested loop.

I often find map/reduce/filter easier to read when using named functions (or lazy data structures ) for intermediary results - depending on the language/runtime that might imply more allocations - or not.

Eg pseudocode:

Integers.filter(//non-obvious prime sieve).sum()

Vs

Primes = Integer.filter(//non-obvious prime sieve)

Primes.sum()

Or lifting the anonymous filter to primes()-filter:

Integers.primes().sum()

Re:Bun v0.8.0 by Tozen on Thursday August 24, 2023 @09:57AM (#37248831)
That's an interesting point. Agree that readability is somewhat subjective, but many programmers find .map, .filter, .reduce, etc... as more convenient and provides clarity as to their intentions. Many languages (like Vlang, Java, Python, etc...), arguably also have them to more closely align themselves with the functional programming paradigm.
Re:Bun v0.8.0 by flohofwoe on Thursday August 24, 2023 @11:14AM (#37249787)
For simple combinations I agree (maybe 2-long chains with very simple conditions and transforms - but for such things loops are also trivial to read).

But I have seen "functional contraptions of horror" where those functions are both chained and nested which were completely undecipherable by mere humans.

And at least from my personal impression, people who are a fan of this type of functional style are also more likely to create such horrors (which they themselves of course find totally readable and superior to "unreadable" loops) - I suspect that there's often a bit of cargo-culting going on.