Sometimes, language programming constructs are just objectively ugly. (Or do I do too much C programming ? No. I don't want to believe that.)
Having to create a syntax that lets three units (condition, true selection, false selection) be associated easily by a reader requires at least 2 operators and is an order of magnitude more awkward than binary operators. While C and Perl5 go for huffman encoding with ? : (which Perl6 is changing to ??
Using 4 operators instead of 2 provided complete bracketing of the operands so there was no need to assign and remember precedence to the operators - that is useful for an operator that is not used often, and the ternary nature requires that the middle term is completly bracketed anyhow and only permits precedence to affect the parsing of the first and last terms.
Guido has taken a middle ground with "true_exp if cond else false_exp" which keeps the longer keyword operators for clarity, but only 2 operators for shorter encoding (than using 4). Switching the order so that the condition is in the middle may have some odd effects on precedence. (It makes the conditional portion unambiguous, but now both result portions need operator precedence rules to determine which parts of the surrounding context is part of one of the two condition result expressions and which is to be applied to whichever result emerges. I don't know whether this is better or worse than the C/perl syntax, offhand.)
Historical huffman encodeing of ternary operator
n1vux on 2006-01-15T03:24:32
While C and Perl5 go for huffman encoding with ? : (which Perl6 is changing to ??:: IIRC), there is history for using a more verbose mechanism, The oldest is the quatenary operator or ternary if in Fortran -
which predates if..then by several years; but neary as old is the ternary operatorif (expr) line_lt, line_eq, line_gtif
in Lispwhich with is pretty well Huffman encoded.(if pred-expr, true-val, false-val)The beautiful thing of Perl is TIMTOWTDI
... if you won't want ternary operators, don't use one. Once Switch.pm is built-into Perl 6, I'll probably use it less.
We will adjust the syntax of what goes inside an 'if' to disallow lambda; currently
if lambda: x:
is accepted but quite useless (it's always true) so this will be disallowed.
I guess backward compatibility is an issue when working with Python. That's something rather important advocacy note to remember.