On 2015-07-23 17:41, Jonathan M Davis wrote:
Maybe, but the ternary operator is a lot less verbose, and from some
other comments in this thread, it sounds like the way they implemented
it in Rust forces you to use braces for single line statements, which
would be a _huge_ downside IMHO.
Scala implements it without those requirements. I looks exactly like in
D, just that it also returns a value.
Also, I think it's getting a lot more interesting when you combine it
with automatically return in a method and optional braces for methods
with a single expression:
def returnType = if (node.isConstructor)
None
else
Some(Type.translate(binding.getReturnType))
Or if you're using pattern matching:
def fromModifier(value: Modifier) = value match {
case Modifier.ABSTRACT => ABSTRACT
case Modifier.STATIC => STATIC
case Modifier.FINAL => FINAL
case _ => NONE
}
BTW, Ruby supports both the ternary operator and statements are expressions.
--
/Jacob Carlborg