4 ms·
> [The tail call optimized] function is starting to look a lot like the orignal for loop solution. It’s not very succinct or elegant anymore. (Brackets mine.)
by midtake 3y ago
> [The tail call optimized] function is starting to look a lot like the orignal for loop solution. It’s not very succinct or elegant anymore.
(Brackets mine.)
I don't know about succinct but I definitely like how it looks a lot more. It's very readable, while the ternary operator one looks illegible at that length. It looks shoehorned in. It's the programming language equivalent of trying to mumble a whole sentence in two syllables.
- k__ 3y agoYes, 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.
- nsonha 3y agoternary is not the important part here, could write it with if and early return too.