Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Ternary vs. Sort vs. Max

by fullermd (Priest)
on Aug 11, 2015 at 04:25 UTC ( #1138112=note: print w/replies, xml ) Need Help??


in reply to Re: Ternary vs. Sort vs. Max
in thread Ternary vs. Sort vs. Max

if ($x < $y ) { $max = $y; } else { $max = $x; }

When faced with the need to write a similar construct (e.g., the condition is too long to make an easily scannable ternary or the like), I find it easier to Just Pick One and then write one conditional, like

$max = $x; if($x < $y) { $max = $y; }

Aside from shorter, I find it actually more descriptive, especially if the other side is an else rather than elseif; "x except when y" as a description reads just like the code.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2020-10-29 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (271 votes). Check out past polls.

    Notices?