DEV Community

Discussion on: We don't need a ternary operator

Collapse
 
snarkypenguin profile image
snarkypenguin

First, pretty well all of the Lisp family have a ternary operator ... the 'if' expression. The observation that the true/false branch operatoronly exists in languages with if-statements is apposite. The people at Bell Labs were mathematicians, and probably felt quite comfortable with the idea of expressions with conditional paths. I am fairly sure that that is their intended purpose.

It is easy to write inscrutable code in any language, and many of the examples of cryptic conditionals we encounter are cryptic because they aren't adequately described.

Knuth's whole aim with 'literate programming' was to make everything clear, and if he can make chunks of raw TeX understandable to a novice (he does), then we can certainly make our conditional expressions intelligible.

It is true that we don't NEED the operator, but why do we NEED anything more that machine code? ... It is because, correctly used, these languages and their constructs make things clearer.

... And part of that 'correctly' is adequate commenting.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Oh, I definitely think we need the functionality. I think part of my intent of the article didn't come across. I mean we don't need a ternary operator because we could instead define two binary operators which are more generic, and also fulfill the conditional evaluation expression.

My concern about parsing is strictly due to the ternary syntax. Once we have binary operators it can be parsed, by machine and humans, the same way as other binaries and thus be even easier to understand.