On Tue, 19 Feb 2002, Nikola Janceski wrote:

> I have old perl code, but it still does what it needs to, and is currently
> being used.
> Now I need to make changes to the code, (about once every 4 months).
> Over time we all code better -- learning better ways to write things,
> clearer ways to write code, write more comments.
> Note: I haven't started using strict or -w yet... soon hopefully with my new
> programs.
>
> Do I rewrite all the code?
> Do I just chuck in the changes and hope for the best?
> Do I cut 'n' paste what I know works (ie subroutines [poorly written]) and
> change the rest?

I've found myself in a similar position, having to wade through some very
poorly written Perl code and having to maintain it.  Here are the things I
do, as independent steps to progressively get the code up to snuff (that
way each little step takes only a little bit of time):

1. add -w and 'use strict' and do the basic code clean up
2. abstract out hard-coded data into variables and/or constants
3. try to make ill-begotten algorithms into more idiomatic Perl style
4a) for a single script, abstract out code into subroutines
5b) for multiple scripts, abstract out code into modules
6) abstract out even more hard-coded data into an external config file

Repeat steps 2-4 until your code is a thing of beauty.  There are more
steps you can add to fine tune this, but those are the basic steps I take,
and each step must pass regression tests (i.e., each step must
functionally do the same thing as the previous steps) to verify you
haven't broken anything.  But testing is a whole 'nother can of worms...

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
Don't sweat it -- it's only ones and zeros.
                -- P. Skelly


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to