News for hackers. Stuff that matters.
Re:Pipe Operator (|>) For JavaScript by vikingerik on Friday January 20, 2023 @11:30AM (#34455459)
This. Temporary variables are the way to go for deconstructing a complex expression like this. Everything is more readable when you put the results of an expression with two to four terms in a well-named variable. Trying to put everything into one giant closed-form expression feels clever and smart, but it's really just getting in the way of the next poor sucker who needs to understand what you were doing.

This works the way human cognition does, by batching. The way humans can fit more items in short-term working memory is to batch up related concepts into one item. This is how chess masters do it - they don't see a piece and look individually at each square it is attacking, they see the entire set of attacked squares as one item. This is why "correct horse battery staple" passwording works - the human doesn't remember twenty-eight individual characters, they remember four words.

Temporary variables follow how human cognition works, particularly when the reader is going to be somebody else's cognition who didn't go through the process of writing it.

Re:Pipe Operator (|>) For JavaScript by sdflhasjd on Friday January 20, 2023 @11:59AM (#34456023)
Temporary variable make debugging easier too.
Re:Pipe Operator (|>) For JavaScript by rwalle on Friday January 20, 2023 @03:39PM (#34459599)
Agreed. It feels great to chain stuff or nest function calls, but then I hate myself when it comes to debugging.
Re:Pipe Operator (|>) For JavaScript by layer8 on Friday January 20, 2023 @01:15PM (#34457246)
I wish I could triple-upvote this.
Re:Pipe Operator (|>) For JavaScript by UlisesAC4 on Friday January 20, 2023 @02:20PM (#34458322)
Pipe is a tool for dealing with batching too.