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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
At first glance, this node appeared to revolve around avoiding problems that mainly exist for a developer if the familar, self-documenting and more maintainable construct "if {} else {}" is discarded and replaced by "?:". It doesn't seem to be about operator precedence in general.

I'm not overjoyed by the examples, either.

$x?$y=1:$y=~s/.*/0/;
What?? How about
my $y = 1; $y = 0 if (!$x);
or, if you actually need a regular expression:
my $y = "a big string of something"; if (!$x) { $y =~ s/somebigoldregex/etc/; }
The above are more readable and make it fairly obvious what is going on. These attributes are very important. If someone (might even be you) has to debug a problem involving your code at 1 am on 5 cups of bad coffee, they're going to understand it faster and will be less likely to want to murder you when they're done. Even better, by writing clearer code you reduce the chances that you or somebody else will need to debug your code in the wee hours in the first place.

This may seem like a harsh response, but I gave you a ++ for your effort and enthusiasm. I would however like to propose that this node comes out of Tutorials, but only until it is reworked into a straightforward "how to use ?:" tutorial which does not even remotely look like it is encouraging the replacement of if/else statements in general. There are (a few) places where the ternary is useful and good, and it's fine to help people write them correctly. Coming up with more realistic examples would be nice. In addition, the title should be changed to something more meaningful.


In reply to Re: Precedence for Idiots by virtualsue
in thread Precedence for Idiots by Melly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found