2 ms·
They explain it here[1] on their discussion forum but still it doesn't make sense to me. If is a statement in every language I know and returns a value, but sti
by _akei 7y ago
They explain it here[1] on their discussion forum but still it doesn't make sense to me. If is a statement in every language I know and returns a value, but still those languages have ternary operator. I suspect they don't want to end up with a language similar to what we already have. They want to be different. Even when it isn't necessary.
[1] https://kotlinlang.org/docs/reference/control-flow.html https://kotlinlang.org/docs/reference/control-flow.html
- nostrademons 7y agoTernary operator is a C-ism. It's common in C, C++, C#, Java, PHP, Swift, Javascript, ActionScript, and related languages, but not present in most of the rest of the PL world. 'if' is an expression in Lisp, Haskell, ML, Scala, Ada, CoffeeScript, SQL etc. A modified form of the if-statement is an expression in Python 3 and Ruby. Go and Pascal have no related concept.
- pkolaczk 7y agoScala doesn't have a ternary operator as well.
- madiathomas 7y agoI haven't used Scala before. What is their reasoning for that?
- melolife 7y agoIn Scala everything is an expression so you just use an if statement: val foo = if(x) y else z
- madiathomas 7y agoThanks. It makes sense because it doesn't have statement. Ternary operator wasn't going to be possible.