|
|
|
|
|
by oriolid
2379 days ago
|
|
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. |
|
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.