Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Difficult code (Resolutions)

by gsiems (Deacon)
on Aug 22, 2003 at 17:29 UTC ( [id://285873]=note: print w/replies, xml ) Need Help??


in reply to Difficult code (Resolutions)

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.

Replies are listed 'Best First'.
Re: Re: Difficult code (Resolutions)
by liz (Monsignor) on Aug 22, 2003 at 18:06 UTC
    4. Ensured that the code still worked the same as before I started.

    How did you do that? Just wondering...

    Liz

      Probably not very well. At that time in my life/learning curve, testing usually consisted of running that portion of the app that used the code being changed, trying various things that the users would do and calling it good. Sometimes I would combine that with logging the imputs/outputs and intermediate values while running the app and the sift through the results to see if it did what I expected. In time I was able to create a test harness for some parts, but realistically, that kind of testing only seemed to work well for those pieces/parts could be isolated from everything else. Very ad-hock. Part of the problem was that almost everything (business rules, data access, etc.), as delivered, was buried in the GUI :-(.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://285873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-03-28 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found