Yes
Funny, that’s what ternary deguars to! Though I think since most of the benefit is in the brevity, the raw switch doesn’t seem to accomplish the task.
However like johnj asked, we’d format such if-else onto the same line. So your snippet with if-else isn’t nearly as bad within template literal: updated.
I’m thinking maybe there’s a nice sweet spot between allowing the ternary syntax, but formatting it to if-else?
Hey I insisted on real world code please =). The problem with theoretical snippets like a ? 1 : 0 is that the character count is dominated by the if-else keywords and braces. In reality, 95% of your code using ternaries aren’t using single character condition, consequent and alternative. We don’t want to accidentally represent the status quo as prettier than it actually is.
That said, I’m interested in seeing your actual usage patterns in your codebases.
I’m not too sure we’d like to compare ourselves to Swift in terms of language complexity, and the fact that even Rust (a language that’s already very complex) removed it does speak volume.
To be clear, you won’t have to manually reword them; the formatter takes care of it. What I’m wondering right now is whether formatting it to a single-line if-else is good enough or not.
A bit of a tangent but, we don’t believe in de-emphasizing such a feature. If it exists it should be documented, and if it’s not documented then it doesn’t exist. We’d rather explicitly document and discourage a pattern rather than discouraging-by-obscurity (though sometime due to the lack of time and out of politeness vs some userland libraries, we do end up doing so).
Maybe…
Please chill a little these days… we value production users’ opinions, but you’re bringing the same argument without examples and with a flamey tone here and elsewhere.
Good point; I forgot to write this down; the deal breaker here in terms of brevity is indeed the braces, though we can’t remove them because of ambiguities: if display if present log() else warn(). Where does the else belong, etc.
