3 ms·
i don't get what is not simple about ternary operator? why is if statement that necessitates multiple assignment statements, involves scoping rules and is obje
by keymone 10y ago
i don't get what is not simple about ternary operator?
why is if statement that necessitates multiple assignment statements, involves scoping rules and is objectively bloated for trivial cases, why is it considered simpler?
it sure is easier to get than an operator due to proximity to natural language, but why tend to people that can't grasp that a statement can be represented as an expression?
- candiodari 10y agoAs a general principle, everything else being equal, less information density is simpler. Ternary operator is quite dense. Think about it: algebra (most of it) is just simple concepts incredibly densely written down and recursively applied. There are very few really complex parts in it, by which I mean there's very few individual steps that take long to understand, there's just so bloody many of them and they link together so incredibly tightly.
- the_af 10y agoBut everything else is not equal; the if-else construct is less clear, more error prone, and you must read it fully to make sure all branches are assignments and that it's therefore logically equivalent to an assignment.