Re: Re: Why PHP sucks - farce or is there a bit of truth?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Always develop like the next person to work on the code is an axe murderer
who know where you live.
On Oct 18, 2013 7:56 PM, "TQ White II" <tq@xxxxxxxxxxxxxxx> wrote:

> If you wrote a nested ternary like that I'd fire your ass.
>
> As one of the main programming philosophers said, the art of programming
> is making your intentions clear to the next programmer.
>
>
> -----------------------------------
>
> TQ White II
> 708-763-0100
>
> >> On Oct 18, 2013, at 2:02 PM, Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx>
> wrote:
> >>
> >> On 10/18/2013 10:33 AM, Robert Cummings wrote:
> >> Hi Jim,
> >>
> >> I'm not sure it's a bug. There are two considerations... should the
> >> first use of the ternary operator feed the first operand of the second,
> >> or should the second use of the ternary operator feed the 3rd operand of
> >> the first use. Visually... which is more correct:
> >> <?php
> >>
> >>     $foo = ($a ? $b : $c) ? $d : $e;  // PHP does this one.
> >>
> >>     $foo = $a ? $b : ($c ? $d : $e);
> >>
> >> ?>
> >>
> >> They both seem perfectly reasonable and so I would say it's my job to
> >> clarify if I don't want to leave it the the vagaries of the developer's
> >> subjective opinion :) To me this isn't a flaw in PHP, but an oversight
> >> by the programmer (because they don't see the ambiguity) or they have an
> >> incorrect assumption that one way is the right way. Either way... do you
> >> think the following makes for readable code?
> >> <?php
> >>
> >>     $foo = $a ? $b : $c ? $d : $e;
> >>
> >> ?>
> >>
> >> Cheers,
> >> Rob.
> > When I write something like this, I expect it to happen from left to
> right.  Always have, always will.  That said I see the 'proper' expectation
> of this statement:
> >
> > $foo = $a ? $b : $c ? $d : $e;
> >
> > as:
> >
> > $foo will be the result of "if $a then $b else if $c then $d else $e;"
> >
> > Why php interprets it differently is just not logical to me.  Of course
> writing something like that with one set of parens solves the riddle as
> well as making it more readable:
> >
> > $foo = $a ? $b : ($c ? $d : $e);
> >
> > As for ambiguity - I don't see it.  Again the literal syntax of the
> ternary if is (IMHO):
> > "if (cond) then (statement) else (other statment)"
> >
> > In your example:
> >      $foo = $a ? $b : $c ? $d : $e;
> > I see it exactly as this:
> > "if $a is true then
> > $b
> > else
> >    if $c is true then
> >    $d
> >    else
> >    $e;"
> >
> > Why should php evaluate the last statement before deciding if it even
> needs that statement?
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux