Keep in mind that Cobra's syntax derives mostly from Python and not from C/C++/C# which is where ?: comes from.
Also, Cobra often kicks things off with a keyword. This even includes many expressions such as "for", "ref", "any" and "all".
Most importantly, from a language design perspective, if a type of expression has an equivalent or analogous statement, I prefer the same keyword: for-statement and for-expression; if-statement and if-expression. If we ever added a conditional looping expression, you can predict it would start with "while".
I did debate on "if(cond, tpart, fpart)" vs. "if cond get tpart else fpart". Note that "get" is already a keyword used for a similar purpose in for-expressions and, of course, "else" is a keyword already used in if-statements. Now that I have used "if(cond, tpart, fpart)", I find that the commas don't provide separation as good as I would like to see. On the plus side "if(,,)" is tighter/shorter than "if get else".
Regarding ??, Cobra has the same thing with ?, but it doesn't have to be doubled since there is no ternary ?: operator that has to be distinguished from.
So any opinions on if(,,) vs. if-get-else?
code = if(.isSigned, -1, 1) * .size
code = (if .isSigned get -1 else 1) * .size # or,
code = .size * if .isSigned get -1 else 1
_superNode = if(.compiler.nodeStack.count > 0, .compiler.nodeStack.peek, _superNode ? nil)
_superNode = if .compiler.nodeStack.count > 0 get .compiler.nodeStack.peek else _superNode ? nil
return if(token.which == 'OPEN_DO', .paramDecls(true), List<of Param>())
return if token.which == 'OPEN_DO' get .paramDecls(true) else List<of Param>()
The if-get-else form is probably done some injustice by the lack of syntax highlighting which would provide better separation:
return if token.which == 'OPEN_DO'
get .paramDecls(true)
else List<of Param>()
See also
for-expression.