Personally, I'd use the term "conventions" rather than "superstitions". (I guess they are superstitions the way there are superstitions about breaking mirrors, which is to say, if I ignore them, I'll fear I'll have seven years of maintenance headaches, er, I mean bad luck.)
Aside from the usual syntactic stuff (how many spaces to indent each level, anyone?), some of mine are:
- Use parens liberally in expressions, to minimize unexpected precedence weirdness. And more importantly, because I find it easier to read code I (or somebody else) has written if I don't have to think through the precedence implications in a complex expression; I can do it, I just don't think it's a good use of my (or anyone else's) time.
- Use descriptive variable names. With a few exceptions my variable names are almost always real word(s) separated by underscores. This way I don't have to worry about whether I called some variable $usraddr or $useraddr; I know it's going to be $user_address. (I also like to think it would be easier to grok for someone who's a non-native English speaker, though that's just speculation.)
- On a similar note, avoid using $i, $j etc. for loop variables. Instead, I use a convention like this:
foreach my $this_address (@address_list) { ... }
- Avoid $_ in most circumstances. I'd rather be explicit about what values I'm using, simply because I find it easier to read later.
- Semicolons after nearly every line (even if they're the only line in an else). Comma after the final element of a hash/array assignment (unless I'm using qw{}).
- use strict, use warnings, test return values of system calls, etc. etc. etc. Any opportunity to let the computer find my errors instead of having to hunt them down myself!
- try to use constant instead of hardcoding any constants in my logic. (I fear I'm far from perfect on this front, though.)
- write POD as I write the code. Write tests before (or at least concurrently with) the code.
- always check CPAN/Perlmonks etc. before going off and writing a "utility" sub -- because somebody has probably already done the work, and quite possibly done it better than I would have.
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.