Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Superstitions? Hmm. After two books, countless lines of code, and training several hundred people I couldn't think of anything I did out of a fear of the supernatural. After reading the examples given, I gave it a bit more thought and came up with a few specific to Perl programming. (I have all kinds of OTHER superstitions with programming in general...) Distinguishing these from style is a bit tough. If I cross the line, excuse me. These are what I do, YMMV.

  • Trailing commas on lists, especially hashes:
    %foo=( bar => 'baz', poit => 'narf', );
  • Things to the rightleft of => I leave unquoted.
  • I only use & with subroutine calls when I intend to take a coderef (Took YEARS to break that Perl 4 habit...) coupled with always using empty parens on sub-calls I avoid nasty @_ side effects.
  • Identifiers in curlies: never quote them. I know the keywords that'll cause hell.
  • Never ever call a subroutine dump()
  • for is for for(;;) loops, foreach is for iteration over hashes and arrays and such.
  • Use extra curlies when dealing with references, even if I don't necessarily need them. (Along the lines of ${$foo}, but usually more complex).
  • Screw precedence: use parens whenever in the least amount of doubt. If I can't remember it from grade school or a common idiom, then someone else can't either.
  • Declare lexicals with my(). Yes, the parens have context effects. If context is important in a my() declaration, I've broken one of my style rules. :)
  • All statements end in semicolons, whether at the end of a block or not.
  • Explicit returns from subs. Loathe that "falling off" return value.
  • Never ever use the .0 release of any software, including Perl. Unless it's from IBM then never use the .1 release.
  • Subroutine definitions go before the code which calls them. (Pascal habit that stuck around.)
  • grep, split, join, open, close, and system always get parens. map and die do not. (Perl 4 habits)
  • The keyword "unlink" causes me to read, and re-read what I'm typing.
  • The following are all viewed with suspicion and avoided when possible: 3-arg open, locales, unicode, v-strings, overloading, and non-fork threads.
  • Never code towards anything discussed in p5p. When the feature's released -- refrain from using it until +.1 release has gone by.
  • In a regex, I don't backwhack anything that I'm not sure is a metacharacter.
  • Never name a script "test".
  • Loop counter variables always go (in order): $i, $j, $k
  • Avoid implicit $_ except in map, grep, for, or while loops that are very small.
  • Objects in their methods are always $self.
  • Quit in vi is spelled :wq
  • The 1 C-Shell command I trust is "/bin/sh"
  • #! lines always have a blank between them and code. Don't want to crowd the magic.
  • Never ever under almost any circumstances do software updates to production systems on a Friday. Never do updates on any day after 3pm.
  • Never trust the vendor's Perl. Build your own. (exception: Activestate for Win32)
  • When looping over an array, do not insert or remove things from the array. Instead push into a temp array and assign afterwards.
Now I break any/all of these when I'm trying to make a point, compress code that's just a side-show, obfuscate, etc..

Update: typo repaired, few late additions

In reply to Re: Coding superstitions by clintp
in thread Coding superstitions by George_Sherston

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (4)
    As of 2018-05-24 22:36 GMT
    Find Nodes?
      Voting Booth?