News for hackers. Stuff that matters.
Re:Using the switch(true) pattern in JavaScript by t-writescode on Monday April 12, 2021 @03:35PM (#26784078)
If you want elses everywhere, how do you protect yourself from nesting hell? I find nesting hell to be far, far, faaaar worse for readability than any of the alternatives, and will move to the early return model to escape all that nesting.
Re:Using the switch(true) pattern in JavaScript by brundolf on Monday April 12, 2021 @03:41PM (#26784157)
I dunno, I just rarely ever find myself nesting more than two or three levels of conditionals even in extreme cases. If my logic really is that complicated, it's probably a sign it needs to be broken up anyway. And if I did need that much branching, I would want to be more explicit about it, not less.

Also - at the very least - you can mimick the "flat" early-return style and just stick some else's in there and call it a day. That's my main point; less so the actual deeper nesting