Re: Ternary operator enhancement for fluent code
| From: | Joey Smith | Date: | Mon, 03 Jul 2000 20:44:47 +0000 |
| Subject: | Re: Ternary operator enhancement for fluent code | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-23371@lists.php.net to get a copy of this message | ||
I'm with Rasmus on this. These operators do not make sense to me at first
glance, and would frustrate any newcomers, IMHO.
On Sat, 1 Jul 2000, waldschrott wrote the following to Rasmus Lerdorf :
> 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.
>
> > 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 opcodes
> > generated 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"...
>
> regards
>
>
>