Like everything else in this World: 'it depends'.

If I am only fixing a bug in the code and there is already a Responsible Party (the Original Author, a System Owner, etc), I try to match the coding style, then send them the patch.

If I have inherited this Hair-Ball, then I have to decide whether the code has a life span longer than the time I am going to be the RP. If I am only the place-holder while we 'end-of-life this Monster as fast as we can', I am comfortable letting sleeping dragons lie. If the Code will out last my curatorship, though, then I feel an obligation to spend time cleaning up the more egregious problems.

I tend to the Verbose style, anyway, so that doesn't bother me as much as 'terse, economical, and uncommented' code. I have always tried to code so that someone on an 0300 Page-from-Operations doesn't have to think to much. The Poor Old Sod might be me, and I know how fast I think at that time of night on no coffee.

So, the first thing I do is wade into the morass and document. My documentation comes in two parts: POD (or equal) and tests. I write up my understanding of the way the code works in the form of tests for the (all too often non-existent) test harness. Once I know that 'what I know' is really true, I write up a POD stanza to go in the code. After a bit, when I begin feel that I really understand that is going on, I start refactoring; Serious Refactoring. I try to spend an hour a day on my Pet; getting the Hair-Ball in shape isn't my primary job here, but I use the refactoring project as a relaxation at the end of the day.

It gives me a certain pleasure to (over the course of six weeks) turn a 10,000 line monolithic block-o-code into a cleaner more maintainable structure. (Only 4,000 lines (including inline POD) consisting of a Base Module to hold the singleton variables, twenty-five Inheritors (one for each of the 'basic' functions), and four Helper/Common Utility Modules. Oh, and 3,000+ tests in the brand spanking new test harness.) Partly, it's because I don't like to have my name associated with slock, and partly it the innate desire to tinker. (And mostly it's the old Boy Scout ethic -- leave the camping site cleaner than when you found it. But...)

I have performed this process maybe a dozen times in the past five years, and I just inherited another opportunity last month. I am going to have loads of fun in 2008.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: Maintence vs. Programming style by Old_Gray_Bear
in thread Maintenance vs. Programming style by apl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":