in reply to Difficult code (Resolutions)

I think anyone who does anything with programming and/or systems administration can feel your pain. I've inherited tons of code from previous admins, varying shell/c/vb/vc++, etc and it's been a riot trying to figure out what's going on.

I believe they fall in several categories and for each one, I've figured out a method that keeps my sanity.

1: Unorganized Q&D - quick and dirty, we've all seen those. No comments, sloppy code, chaotic design, definitely needs being rewritten as soon as possible. Filed away for later perusal.

2: Organized Q&D - at least an attempt to have a cleaner code of the previous statement, some comments, however brief, spaced/indented code in most areas. Some sections might need work but overall, functional and not necessarily needing rewriting.

3: Organized code in development - development code/scripting that looks good but may have design structures that are different than yours and since understanding what every line does, a possible rewrite using existing code but substituting your function/variable names can be done. Also might rewrite just for brevity/improvement/efficiency/etc but not needed due to development. This is common of the "if it ain't broke, don't fix it" clause.

4: Unorganized Q&D in production - same as point 1, but in production and is desparately in need of an immediate rewrite, however on-the-fly that may be. Bug fix to keep going, but filed immediately for cleaner/improved code.

5: Semi-organized lengthy inherited code in production - hardest kind to maintain. Production states that it's been added on and maintained for the duration by several groups/people and is good in some areas and possibly horrid in others. Possible rewrites through CVS/SourceSafe/etc are worthy, but only if the entire thing is done, otherwise it's just bug-fix and move on.

IMHO, I try to rewrite everything that isn't well-documented. I learned rather quick that as long as I know the function of the script/code, I can probably rewrite it faster than trying to figure out what variable $xn2 does. That's the beauty of the call-sign of perl - "There's always another way to do it". That applies to everything in code, production and development alike. And fortunately, my sanity's been able to be kept although there are times when I really want to scream 'WTF is this?' when looking at some obscure non-documented code buried in the archives of legacy programs.