I mentioned I am refactoring some code for a client. My first step was reformatting (perltidy and some by-hand stuff), and fixing up some minor code mistakes and consolidation along the way. I'll tell ya, formatting helps wonders. Spending the time to do proper indenting, make some things more consistent, and more visually pleasing can make speghetti look much more like ziti.
Now I can start breaking out some redundant code and making it modular. The guy(s) who originally wrote this were, er.. not the greatest with code design. Sort of half Matt Wright-esque and half "Hey, noone else will ever work on this". Of course, now I am maintaining it so I feel the need to better it for my own sanity and time.
There are thousands of lines of code in about a dozen scripts. No warnings, no stricture, not even using CGI.pm (except for sections I added) or ANY (that's right NONE) modules from CPAN (again, except for my sections) aside from DBI. Thank god they didn't reinvent DBI along with everything else!!
So, now I need to plan how to keep making the code better without completely rewriting it. As I went through the code I noticed some obvious things to consolidate... so I guess I'll start there and see where it goes. At the very least, I can now visually follow the code!
mmmmmmm.... ziti
One of my greatest professional pleasures is deleting code while retaining necessary behavior. Sometimes I worry someone will sit me down against a generative algorithm and ask me to refactor two similar, nasty subroutines and I'll be there the rest of my life....
Re:Spaghetti Code
KM on 2003-07-30T20:17:03
I got great satisfaction taking 30 line blocks and condensing them to 5-10 lines. I didn't get to delete anything yet with replacing it.. the code is one of these "Um, where did this variable come from?? DO I NEED IT??" works of art.
I'll likely turn on warnings and stricture and work through the errors which will appear. Joy.