I've been writing code professionally for nearly a decade now (Dot-Com 1.0 represent!). I learned the hard way that being a professional developer is about so much more than writing code. Or, for that matter, writing 'good' code.
In making minor changes to a script that has existed at my current company for a very long time, I came across a special block of code. This code block is a prime example of what I believe in when it comes to professional development.
The actual method name was changed to protect the egos of the guilty, in the (remote) possibility that they're here.
sub SUB_NAME {
return $a->[3] <=> $b->[3] or
$a->[2] <=> $b->[2] or
$a->[1] <=> $b->[1] or
$a->[0] <=> $b->[0] or
$a->[4] <=> $b->[4];
}
Several things to note about this sub:
- There is not a lick of documentation or commentary about what this method does.
- The actual sub name has nothing to do with what the sub does.
- The code calling the sub doesn't have any documentation or commentary suggesting use either.
- In fact, the code is not called *at all*, as best I can tell. (major eval() & function pointer abuse all over the codebase)
I could really go on and on about what's wrong with the code itself, but that's not really the point.
We've all written sloppy code. I'm as guilty of it as anyone else is. We all try to write the best code we can, but sometimes the first draft is good enough, deadline pressure arises, and things are left behind. It happens.
But at this point in my career, I've learned a few things:
- You're going to have to support it in the future, document it. At least say *something* about why this block of code exists.
- If you're not going to be supporting it, someone else will. You better hope they're not filled with a murderous rage when they come across it.
Perhaps I'm just a little annoyed - in the end, this isn't close to the worst offender amongst all the code we're cleaning up over here. In fact, it's an inconsequential problem. But this one just stuck in my craw. And so, I post.
To those of you still early on in your careers, remember: whatever you write, others will read. And likely, they'll have to support it. Show some respect for the poor soul who will fill your shoes some day in the future. :)
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.