7 ms·
Yes, every language should have if-expressions. Don't know what they were thinking with the ternary operator.
by k__ 3y ago
Yes, every language should have if-expressions. Don't know what they were thinking with the ternary operator.
- JonChesterfield 3y agoOne reason I've heard for the statement vs expression distinction, where one deliberately makes a mess of the syntax uniformity, is that it helps diagnostics of programming errors. That is, by demanding spurious restrictions on syntax and generally making code more annoying to write, you get to detect more constructs as probably bad. Line noise - semicolons in C, colons in python - is the same idea. Earlier diagnostics of code that probably wasn't intended. I don't find this remotely compelling as a language design choice but it's the best justification I've come across for why so many have the extra obfuscation between programmer and AST. Specifically, why would one optimise for ease of reading invalid code instead of for ease of reading valid code. Madness. But popular.
- recursive 3y agoHow are if-expressions different from the conditional operator? I thought one was a concrete implementation of the other.
- djur 3y ago"if" comes before the condition, "?" comes after. For a lot of people this seems to significantly improve readability.