Re:Statements vs. Expressions
by dtagames on Tuesday July 12, 2022 @12:15PM
(#32072077)
Ah. Was just thinking of JS/TS in this case. Good point.
[ Parent
| on HN ]
Something which was once a statement and started with a keyword can become an expression in a new version of a language.
For example, in C# 7, throws were made into expressions to allow syntax like this:
return a ? b : throw new Exception();
So I wouldn't rely on this rule.Ouch! I like to rely on the ternary operator as a cheat for if/then just as much as the next guy, but that qualifies as abuse, lol!
I wouldn't say that's abuse and I missed that many many times in JS/TS, for example on unreachable variants in tagged enums. This usually turns into null with a null check afterwards just to throw the exception, which is more verbose for no reason.