Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

That's not superstition. It's called 'defensive programming', and it's the kind of habit programmers tend to aquire after a few trips down the razor blade of life. You're adding information the compiler doesn't need, but so what? Programming languages aren't for computers anyway.. they're for humans.

If you want to talk about something we could eliminate, let's talk about whitespace. The compiler ignores it, except in very special cases like searching for the closing delimiter of a here document. Yet programmers wage holy wars about whether to indent braces like so:

if (&condition) { &yes; } else { &no; }
or like so:
if (&condition) { &yes; } else { &no; }
when all the compiler sees is:
if(&condition){&yes;}else{&no;}

And technically, those semicolons aren't necessary either (nor are the braces, now that I think about it). I always use them, though, because experience has shown that I may want to put another statement into one of those blocks, and it's easier to terminate the expression now than to go back and do it later. I always use a trailing comma in list definitions:

@list = ( 'item one', 'item two', 'item three', ## <- unnecessary punctuation );

for exactly the same reason.

High-level code is for humans. If it wasn't, we'd still be using machine code. Redundant information, which the compiler ignores, can still convey information to humans. Conventions like 'always quote string literals' and 'use meaningful variable names' make code more useful for humans, even if they don't do anything for the compiler.

Instead of worrying about whether such things are necessary, ask yourself how much they cost. So the compiler optimizes out a few tokens while it's building the syntax tree. Big deal. It's not worth retraining a habit just to save that dozen clock cycles or so. And if you personally find the code slightly more stable or readable, the payoff is worth the cost.


In reply to Re: Coding superstitions by mstone
in thread Coding superstitions 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (4)
    As of 2014-11-27 21:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (188 votes), past polls