I try to follow the guideline of "writing code to make life easier for the poor fellow who may need to debug it". That poor fellow is often me; after a few weeks, my own code begins to look to me as unfamiliar as anyone else's.
That's easier said than done, though. It takes practice to identify what will make debugging easier. For example, it took me some time to understand that the reason for avoiding global variables was to facilitate debugging, since to fully grok the state of such a variable one must, in principle, examine the code for the entire package, which can be anywhere. Once I realized this, it became clear that a lexical whose scope is a huge file is scarcely better than a package variable (aside from not being able to modify it from code in a different file), and I understood that the goal of shrinking the scope of variables is to make their fates obvious "at a glance", a goal that makes sense only to someone who knows firsthand the joys of debugging.
One implication of the "code for debugging" dictum that I find difficult to follow is to resist the golfish temptation to subject my code to multiple rounds of compression. Yes, succinct code can be clearer than long-winded code (largely because long-winded code is often a symptom of not fully understanding the problem in the first place), but it can also slide into obfuscation. Unfortunately, it is very difficult to know where to draw the line, because at the time of coding, one is so familiar with the problem that it is almost impossible to put one self in the shoes of someone seeing one's wonderfully concise gems for the first time. As I already remarked, that "someone" is often me a few weeks later.
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:
Outside of code tags, you may need to use entities for some characters:
- 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
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||