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. | [reply] |
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:
- As Beatnik suggests, you want to try to understand what the scripts are doing first
- Now try to understand what the tools the scripts need to accomplish their respective tasks are
- 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)
- 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
- 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
| [reply] |
Try to go OO/modular.
I'm nearly there with all the concepts myself - Damian Conway's book is an absolute gem (prepare to read it several times :)
And when I am, everything's going OO and modular for two reasons:
- Perl6 is more OO, so planning ahead
- keeping variables in ordered namespaces helps one hell of a lot - If you comment objects/modules well, you can amend easily without worrying about affecting code that calls it from another namespace (because that code knows the rules of your module, right :) - so, when porting to Perl6, I really hope I just have to mess around with a few modules :)
.02
cLive ;-)
| [reply] |
Another approach short of rewriting all the scripts from scratch
(probably not a practical approach for you) would be
to write tests for the scripts.
That way, you will understand what they do, and you will be in a position
where you can change/patch/fix them without nightmares
of production stopping at midnight.
This approach has the added advantage that it looks
very professional to outsiders (what rewriting typically does not do). And in fact, it is professional to do it like that. It will be a lot of work, though.
Update: chromatic reminded me to point out that well-written tests can serve as or aid specification and documentation. Yes, this is certainly true. Thanks, chromatic!
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
| [reply] |