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

Re: Ternary operators: a hinderance, not a help

by revdiablo (Prior)
on Aug 09, 2005 at 15:33 UTC ( [id://482255]=note: print w/replies, xml ) Need Help??


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

My opinion of the ternary has changed throughout the years. I don't really know why, but it has. It might change again, so don't hold me accountable for this in the future. :-) For a long time, I was on your side of the camp. I really didn't like it at all. I thought it was ugly and pointless.

Nowadays I have swung back to the other side. As long as it is used for assignment, and not for side-effects, I don't see a problem with it. In fact, in some circumstances I think it's quite nice. It handles the assignment in one semantic unit (i.e. a single statement), rather than having the default value and the possible new value split up among two statements. Note, nowhere did I mention anything about saving a line of code. I'm all abount semantics, baby. Usually I even spread the ternary out into 3 lines of code, which I find more easily readable:

my $variable = $test ? $value : 0;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found