in reply to How to modify existing code

If it's spaghetti code, you'll probably be better of rewriting the script from scratch, something I rephrase as logic porting. Understand what it does, how it does it (file wise, system wise,...) and start hacking. The idea is ofcourse to make it cleaner, more functional, probably loads more commented, faster??, more efficient. Remember the poor guy which will need to port that same code to Perl6 :)) I doubt you'll be able to do that based on spaghetti code :) I've found it inspiring rewriting scripts from scratch over and over again (if time permits me).

Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.

Replies are listed 'Best First'.
Re: Re: How to modify existing code
by jreades (Friar) on Jun 20, 2001 at 21:11 UTC

    rewriting++

    100 different scripts sounds like a nightmare (especially if you didn't write them), but I suspect that you're likely to find a lot of overlap between various scripts.

    Here's a possible sequence of events for the least painless port:

    1. As Beatnik suggests, you want to try to understand what the scripts are doing first
    2. Now try to understand what the tools the scripts need to accomplish their respective tasks are
    3. Now try to highlight areas for re-use -- e.g. database access wrappers for DBI, printing feedback to the user (either HTML, text, or graphical)
    4. These reusable elements are likely to be good candidates for either modules or objects, depending on what they do
      • Remember that objects are normally wrappers to data,
      • while modules are ways of reusing useful functions
      • This is very loose, but what I'm getting at is that in a scripting-oriented language, not everything has to be, nor should be, an object
    5. Comment, comment, comment -- how many times have you come back to your own code only to say: "What the hell was I trying to do here?"

    HTH