Whenever I see an article comparing a market leader with an underdog, I always know that the article will be biased against the market leader. It is human nature to root for the underdog. What was the reason for not starting with variables II? I suspect the author wanted to manipulate our minds right there. It is obvious that Java version is the better of the two but they decided to start with a variable with final. Ternary operator for Kotlin doesn't look like ternary to me. It is just an inline if\else.
Why is variables II better in Java? Its almost the same with advantage on Kotlin side with type inference. Also ternary operator isnt needed in Kotlin since if/else itself can return value, so its just example to show so people dont try to look for it in Kotlin. Overall its not even an article, its just a showcase of differences in syntax and idioms in both languages, i cant fathom how could you be manipulated with that.
Clear and concise to someone new to programming. Also less typing. Comparison of an a market leader to a new entrant is designed to make you switch from market leader to new entrant in the market.
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.
Ternary 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.
What's the difference between ternary operator and inline if/else? Is there even any reason for if/else that doesn't return a value (that may be void/unit/similar)?
It is also obvious that Java version of the variable syntax is awful and just asking for unintentional modification.
> What's the difference between ternary operator and inline if/else?
There is no difference. Ternary operator is a syntactic sugar for if/else.
> Is there even any reason for if/else that doesn't return a value (that may be void/unit/similar)?
Main reason why an if statement returns a value is because it is used to test if condition is true or false. If it returns other values, it was going to make it more complicated. Especially when you have an if statement with multiple conditions that must be ORed or ANDed.
What is awful about the variable syntax? This syntax was copied directly from C language.
> Main reason why an if statement returns a value is because it is used to test if condition is true or false.
Uh, no. The condition itself is true or false. The return value is useful for assigning, passing as parameter, etc. Non-returning if requires dealing with temporary variable, which itself is verbose, doesn't automatically get assigned in both branches, doesn't play nice with C++-style move semantics, etc.
> What is awful about the variable syntax? This syntax was copied directly from C language.
C language is awful, but at least they have the excuse that nobody knew better in the 70s and const kind of works even the syntax is a bit complicated.