If a ?-: conditional has at least one argument that needs braces, the ?-: conditional should be converted to if-else. The converse also seems good: convert if-else expressions to ?-: when all three arguments are simple.
Going further, to converting any ?-: that doesn't fit on one line is also probably a good idea, but I guess harder to implement.
I hadn't considered this. I like it.
Right now, there is one benefit to the current approach for ternary conditionals. They are always preserved by the pretty printer no matter what because they have a separate AST representation. However, there are many simple if/then expressions in OCaml code that would look so much better if converted to ternaries, so I like your proposal.
Actually, if simple if-else expressions format on one line, then I think that the value of ternaries drops considerably. But that's just probably just my preference.
The under-riding consideration here is that it is generally good if there are fewer equivalent ways to write the same thing, so that programmers don't have to spend time thinking about which to choose. There are always more than the syntax can help with, but every little helps.
The under-riding consideration here is that it is generally good if there are fewer equivalent ways to write the same thing, so that programmers don't have to spend time thinking about which to choose.
I wish this were the motto of a (more functional) language besides Python 馃挀 The potential for that to be Reason is why I'm watching closely. I feel like TIMTOWDTI is a consternation to many developers who just want one鈥攁nd preferably only one鈥攐bvious (right) way to do it.
I'd be in favor of not having ternary. Especially since you can write an if in one line, without braces.
see also #1700
Most helpful comment
I'd be in favor of not having ternary. Especially since you can write an if in one line, without braces.