Re: Ternary operator enhancement for fluent code
| From: | Andi Gutmans | Date: | Sat, 01 Jul 2000 20:13:48 +0000 |
| Subject: | Re: Ternary operator enhancement for fluent code | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-23170@lists.php.net to get a copy of this message | ||
At 09:58 PM 7/1/00 +0200, waldschrott wrote:
Hi Rasmus, Hm, you´re not right, not forcible. Not every enhancement makes sense. But if no one adds functionality to a livinig language there´s no progress... I think at least !! and ?? are worth a try, I could apply them very often and it isn´t as complicated as you promoted it: if(!!$a) { $b = $c ?&? $d; } if variable $a not equals FALSE, set var $b to $c(if set) else to $d. Nothing complicated in here, I did know that Andi,you and co wouldn´t like them (deviation from C,Java...), thus I´ve only posted the most important one (?? op) - if you think of PHP better beeing easier to read, without the need to think, for everyone than adding mighty operators for experienced ones, gaining sore fingers by typing: if ($var_1!==FALSE) { if (isset($object1->current_state) $retval=$object1->current_state; else $ret=$object2->current_state; } what could be done using if (!!$var_1) $ret= $object1->current_state ?&? $object2->current_state; , then I`ll possibly have no chance at all.You won't have a chance using such cryptic syntax. It is not worth the loss in readability and "compatibility" to other languages.
Actually Rasmus isn't 100% right here. Theoretically it might allow us to implement them a tad bit faster but you will most probably not notice a difference in overall script performance.He will curse you and your family since this does not look like anything else in any other language, and it is difficult to look up !! or ?&? in an online manual.That´s not true, just go to operators->comparison op->(...) and you´ll find "!!" and "??", not significantly harder than trying to find "?:" From a performance point of view there is minimal gain here as the opcodesgenerated will be the same and the 6 or 8 less bytes the parse has to parse is insignificant.I´ll have to trust you, I don´t know much about these internals.
At least !! is an enhancement that would fit to PHPs peculiarities like "automatic conversion"...If you think !! is peculiar then that is a good reason not to add it :P Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/