When you start to bump into any of these concerns, I’d recommending extracting the functions themselves, rather than breaking the pipeline… which was not something mentioned or explored.
One can definitely go overboard with this, though. I have had to read a lot of code where someone broke something up into several functions that only had the effective of forcing me to constantly bounce around all over source file to figure out what was going on without improving clarity at all.
Ugh, SonarQube with the cognitive complexity check.
“Instead of having 50 lines where all logic is right here, I’mma need you to break it up into 10 separate functions so it’s a massive pain in the ass to figure out what the fuck is going on”
I understand the reasoning but sometimes it’s way more confusing to split up complex logic instead of just having it all in one place.
SonarQube can eat my whole asshole.
As with everything: Balance is the key.
Only tangentially related, but I dislike that
filterandmapare eager in JS. Meaning if you chain them, you allocate N-1 arrays that are being discarded right away. C#, Java and Rust have the right approach.Are they eager even with generators?
You made me go down the rabbit hole with that question. TIL the very same methods exist on
Iterator’s prototype. They aren’t eager, no.You can get an iterator out of an array with Array.prototype[Symbol.iterator]() and you can collect an iterator into an array with Iterator.prototype.toArray().
One reason you may not have known this is that these (iterator methods, not the Iterator itself) are newish additions to Javascript and only available in all the big browsers for just over 1 year.
Ugh, I absolutely hate reading code with a ton of variables that are only used once, because each introduction of a variable is a new thing that I have to first parse and then track to figure out what it does. I would much rather read a pipeline that expresses what is going on concisely without introducing extraneous elements. In particular, I thought that the pipeline at the start of the article was perfectly clear and did not need any of the subsequent modifications.
Throwaway variables are an antipattern. Say what you will about Airbnb as a company, but their JS style guide is fucking dead on.
I think using a better variable name for the “pipeline” result is a much better approach






