Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: if statement confusion

by eyepopslikeamosquito (Canon)
on Jun 12, 2012 at 13:26 UTC ( #975805=note: print w/ replies, xml ) Need Help??


in reply to Re: if statement confusion
in thread if statement confusion

I'm afraid that I would come fairly unglued if I saw such an "economical" attempt to write an if statement in the fewest number of characters. The difference makes absolutely no difference at all to the Perl compiler, but it has the very human difference of being utterly un-maintainable.
Ironically, the original code:
6 < 8 ? $ans = "true" : $ans = "false";
is "un-maintainable" not because it is too short but because it is not short enough! Writing it like this:
$ans = 6 < 8 ? "true" : "false";
is perfectly clear and, by eliminating the (error-prone) repeated use of $ans, maintainability is improved.

Since you suggested an if statement, I certainly hope you're not suggesting replacing it with:

if (6 < 8) { $ans = "true"; } else { $ans = "false"; }
This version has the same dubious violation of of DRY as the original, and so is less "maintainable" than the improved simple ternary version IMHO.


Comment on Re^2: if statement confusion
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-08-30 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls