Re: Ternary operator enhancement for fluent code

From: Date: Sun, 02 Jul 2000 09:47:50 +0000
Subject: Re: Ternary operator enhancement for fluent code
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-23203@lists.php.net to get a copy of this message
On Sat, Jul 01, 2000 at 08:06:50AM -0700, Rasmus Lerdorf wrote: > I really don't like magical operators like this. It may seem like a nice > thing when you are sitting there working on thousands of lines of code, > but when the next poor soul comes along and sees: > > if(!!$a) { $b = $c ?&? $d; } I thought a little bit about it and now think, that rasmus is right here. I am one of those who write thousands of lines of code, and therefore it whould have been a nice thing for me. But I don't think that I'll open source my work, so there would be no `poor soul'. > 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. > > 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. No, there whould be fewer opcodes, but the overall performance gain whould not be noticeable unless it were in a deeply nested loops. Now, if it had been implemented for the hardcore php developers for the use in closed source projects, nobody could forbid it for open source projects, in which the use of those cryptic operators would harm php in the sense of newbie confusion. So there whould be two possible ways to go: 1. make hardcore php devels happy 2. be newbies friendly Perl choose the first, php the second. The answer should be clear now. > On Sat, 1 Jul 2000, waldschrott wrote: > > > Hi Jade, > > if you liked that idea, I´ll tell you which enhancement I´d found very > > helpful (I collected them working on thousands lines of code, they´re > > practically orientated and will be very useful): > > > > > > (1) > > PROPSED SYNTAX !!$val > > MEANING extended negation w check > > LONG EXPRESSION $val!==FALSE > > > > (2) > > PROPSED SYNTAX $val1 ?? $val2 > > MEANING > > Reduce-enhanced ternary op > > LONG EXPRESSION > > 1. if (!($pos=$val)) $pos=$val2; > > 2. return $pos; > > > > (3) > > PROPSED SYNTAX $val1 ??? $val2 > > MEANING > > Reduce-enhanced ternary op, 0 safe > > > > LONG EXPRESSION 1. if (($pos=$val)!==FALSE) $pos=$val2; > > 2. return $pos; > > > > (4) > > PROPSED SYNTAX $val1 ?&? $val2 (found no better syntax) > > MEANING > > Reduce-enhanced ternary op, 0 safe > > > > LONG EXPRESSION 1. $pos= isset($val) ? $val : $val2; > > 2. return $pos; > > > > > > Overall these improvements would mean: > > - smaller code > > - faster executing > > - no additional ambiguities > > That means: Faster and better development for the experienced and if > > documented thoroughly even for newbies and intermediates... > > > > That´s optimizations who wouldn´t love them? > > I don´t see any negative aspects and I do not think these additional > > operators (which would simplify PHPs usage and increase performance) > > will be too complicated to understand. > > > > -- =============================================================================== Jade Nicoletti Nicoletti Net Services Tel. 01 240 4774 Geschäftsleitung Postfach 2519 Fax 01 240 4775 System-Administration 8021 Zürich ============================================[ Weitere Infos: http://nns.ch/ ]==

« previous php.dev (#23203) next »