Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Ternary operators: a hinderance, not a help

by spiritway (Vicar)
on Aug 09, 2005 at 18:42 UTC ( [id://482363]=note: print w/replies, xml ) Need Help??


in reply to Ternary operators: a hinderance, not a help

I think the ternary operator is just fine for simple tasks. It gets confusing, though, when someone shows their coding machismo by doing something like:

 $number= $test ? $value : ($something_else ? $foo : $bar)...

Back in the days of dumb compilers it made some sense to write things like that, on the theory that the compiler's output would be more efficient. You had to show it how to optimize. Now it's not necessary. We're writing code for humans to read, not for compilers. Clarity is (IMNSHO) more important than efficiency, now that compilers generally are capable of outputting efficient machine code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://482363]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2024-04-23 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found