Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The rule, "the smaller part of a conditional should go first" conflicts with the rule, "the expected path should go first". The justification for the second rule is that it makes the code more natural to skim. That is, of course, secondary to wanting to make it clear what is part of the conditional. But it is not totally irrelevant.

I usually put the expected result first, and avoid the size issue by moving the body of long blocks into functions. That probably works 95% of the time. The exceptions are mainly cases where I have nested control logic that I want to keep in one place, or situations where I need to inline a long piece of text (eg an SQL statement). Then I will move the shortest block first for the reason that you give.

So my rules in order of precedence are to make it obvious what belongs to the conditional, and then to make the most common flow of the program match the natural flow of skimming. But the more important can usually be satisfied without harming the second, and I do.


In reply to Re (tilly) 4: Defensive Programming by tilly
in thread Defensive Programming by George_Sherston

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 rifling through the Monastery: (5)
As of 2024-04-23 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found