In my experience, my own particular brand of defensive programming is to defend me from myself. I can almost guarantee that most of my mistakes come at 2:00AM, after an evening of caffiene jolts and with music blaring into my headphones.
My own list of defenses are probably very similar to most of the other monks (I have seen quite a few) so I won't go into much detail. Heres one example of the things I do:
# Number 1: the trailing return
sub blah
{
if($somevar == $somevalue)
{
return $this;
}
else
{
return $that;
}
return;
}
I had an argument with my boss for a while about doing this. But it does nothing, harms nooone so why not (well that was my argument :P).
I think it is easy to confuse defensive programming with secure programming but I see them as two separate disciplines.
Defensive programming should, in my opinion, be about how you program. Thus it allows you to affect the design of the program as well as how you implement it. After all, if an algorithm or code snippet (more likely) goes against your own brand of superstition then who would honestly
not re-write it? I know that the first thing I would do with code from another person is go through it with a fine toothcomb.
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.