I used to do maintenance on a in-house system that had originally been developed by some consultants (I used to not like consultants as a result of that). Parts of it were reasonably well written and other parts were really, really ugly.

While there were a few cases where entire chunks of the app got ripped/replaced as they were too horribly broken to be fixed incrementally, my approach was mostly to fix *only* the piece that needed to changing (that piece, that whole piece, and mostly nothing but that piece). FWIW, I considered a piece to be a function, subroutine, and/or method.

For that piece,

1. First I'd fix the indenting/whitespace.

2. Then I'd pick a variable, figure out a better name and rename it-- I tended to search/replace one by one and checked how the variable was being used as I went. It was amazing how much dead code there was in the form of

   declare $variable...
   set $variable...
   set $variable again...
   set $variable yet again...
   end of code piece-- value of $variable never used.

3. Repeated step 2 for all variables, removing dead sections and unused variables as they were found.

4. Ensured that the code still worked the same as before I started.

5. Refactored the piece if it made sense to do so.

6. Tested it again.

7. Made my change.

8. Tested it again.

Using this approach, I never rewrote the whole thing application, just the pieces that needed changes whether those changes were for bug fixes or new/different functionality.

Some observations that I made alng the way was that there tended to be a correlation between:
1. formatting and code quality (poor formatting ~ poor quality),
2. global variable useage and code quality (lot's of globals used ~ poor quality), and
3. unused variables and code quality (lot's of unused variables ~ poor quality).

my 2 cents.

The box said "Requires Windows 98 or better" so I installed Linux.


In reply to Re: Difficult code (Resolutions) by gsiems
in thread Difficult code (Resolutions) by xChauncey

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.