|
Posted by Jerry Stuckle on 05/11/05 15:06
Jason F. wrote:
> Andrew DeFaria wrote:
>
>> Jason F. wrote:
>>
>>> That's the ternary operator, which you'll find in a lot of languages
>>> besides just PHP.
>>>
>>> The above example is exactly equivalent to:
>>>
>>> if (isset($xyz)) {
>>> $string = $xyz;
>>> } else {
>>> $string = "something else";
>>> }
>>>
>>> In the interest of *easily readable code* I would recommend that you
>>> try *NOT* to use the ternary much just to appear clever. Sure, it's
>>> more compact, but it takes a couple extra seconds to figure out
>>> what's going on VS an if/else.
>>
>>
>>
>> It takes a couple of extra seconds (actually about .5 seconds) the
>> first few times. After that it's quite natural and no less confusing
>> than the if you constructed above.
>
>
> The ternary always takes extra time to grok, even if you've been
> [ab]using it for years. Many agree that the Best Practice(TM) is to not
> use it, or to at least limit its use to very simple cases. The worst are
> the "clever" nested ternaries that span multiple lines.
I agree with Andrew. It takes me no extra time to understand, and I
find it *very* natural. If anything, I find it *faster* to understand
than your if construct above.
You and some others may agree that you shouldn't use it. Fine. But
that doesn't make it bad. There are a lot of other programmers who find
it quite easy and natural.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|