Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Ternary vs. Sort vs. Max

by fullermd (Priest)
on Aug 11, 2015 at 04:25 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1138112]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-28 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found