Re:Verb-Noun vs. Noun-Verb
by greggman2 on Thursday October 17, 2019 @12:29AM
(#21278918)
I know most will disagree but I find code the above hard to read. I'd much prefer
Or some such thing. The more complex the chain the harder it is for me to read. Does anyone else have that experience?
[ Parent
| on HN ]
There's a spectrum here. Someone even more explicit than you may insist that `average` should be split up into explicit bindings for the mapping to Int, the sum, and the count.
Also, for non-toy examples, there are real benefits to composing transformations, so that you don't pay the memory and performance costs of assigning intermediate sequences.
Re:Verb-Noun vs. Noun-Verb
by ThrowawayR2 on Saturday October 19, 2019 @08:35AM
(#21298143)
You're not alone; those long chains are annoying to decipher. The other benefit of what you wrote is that if you have to track down a bug in the chain, you can actually examine the intermediate variables directly instead of having to pick apart a long chain so that a variable is exposed for you to look at in the debugger.
Re:Verb-Noun vs. Noun-Verb
by joostdevries on Thursday October 17, 2019 @02:18AM
(#21279400)
I agree. Naming parts of your code is important.
An alternative to named local vals is to either use named functions instead of lambdas: people.filter(olderThan50) or (I use Kotlin) use named extension functions: people.countOlderThan50()
Re:Verb-Noun vs. Noun-Verb
by splittingTimes on Thursday October 17, 2019 @04:40AM
(#21280048)
In any nontrivial application, doing this for many of your types, does this not bloat your API considerably, which adds to the cognitive load?