Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Ternary operators: a hinderance, not a help

by adrianh (Chancellor)
on Aug 10, 2005 at 10:48 UTC ( [id://482561]=note: print w/replies, xml ) Need Help??


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

Now, in this contrived example, it's pretty obvious to see what's going on and what's being assigned where. Consider, however, extending this to a more complex real-world scenario, involving accessing elements in deep data structures, subroutines to format numbers, regular expressions and the like. Clarity, maintainability and even code elegance are quickly lost, all for the sake of a few keystrokes and a newline, unless the person doing the coding is very careful about how he uses the operator.

Very careful? Is it really that hard to see when if/then/else is going to be less clear than the ternary operator (or vice versa)?

Use whichever one's the clearest in a particular situation. Saying that one or the other is less clear or maintainable without a particular context is just silly :-)

  • Comment on Re: Ternary operators: a hinderance, not a help

Log In?
Username:
Password:

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

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

    No recent polls found