News for hackers. Stuff that matters.
Re:Using the switch(true) pattern in JavaScript by csmattryder on Monday April 12, 2021 @10:32AM (#26779866)
Spare a thought for the junior/mid-level devs who don't understand clever patterns, and the seniors who haven't read the same blog posts as the implementor of the switch(true).

Completely agree, it's like writing readable prose, understand your audience.

That said, give me proper pattern matching in JS. Hard to live with languages that haven't caught up yet.

Re:Using the switch(true) pattern in JavaScript by nicoburns on Monday April 12, 2021 @10:43AM (#26779965)
> That said, give me proper pattern matching in JS. Hard to live with languages that haven't caught up yet.

I really want this. Along with switch being as expression. Seems like something that JavaScript is obviously missing.

Re:Using the switch(true) pattern in JavaScript by deergomoo on Monday April 12, 2021 @06:03PM (#26785741)
> Along with switch being as expression

Even PHP has this now, albeit with a different keyword (match) due to existing switch semantics being pretty bad

Re:Using the switch(true) pattern in JavaScript by jessaustin on Monday April 12, 2021 @05:23PM (#26785383)
I really want... switch being as expression.

Unfortunately JavaScript still hasn't caught up with CoffeeScript.

Re:Using the switch(true) pattern in JavaScript by throwanem on Monday April 12, 2021 @07:29PM (#26786430)
Of course, you can't evaluate prose in a REPL and see for yourself what it does.

I agree that overly clever code is always to be avoided. But is this really overly clever? I wouldn't expect an engineer early in their career necessarily to understand on sight what it does. But I might worry a little for one who couldn't figure it out through experiment.