I’ll let you in on a dirty secret: my first paid programming task was to make custom modifications to an oscommerce shopping cart. I cut my teeth on PHP that weekend and learned through trial by fire how much good, clean code (with no global variables!) matters, and how much it really SUCKS when everything is in the global scope. I always died a little inside each time I had to make a modification… I once started refactoring the code on the side, but gave up after a month. It was just so… intense!
Anyhow, my days of modifying oscommerce carts finally came to an end. My current job has me doing java web development (which is another beast on its own) and although I do some php related gigs on the side from time to time, always opted to use Magneto or other solutions for my shopping cart needs. Today I wondered… did oscommerce 3.0 ever release?
A quick journey to their site revealed that, no, 2.2 is STILL the latest stable release (which is what it was when I first messed with in 2004/2005 I believe) and the last release of oscommerce 3.0 (Alpha 4) was over a year and a half ago… ouch! How did this happen? Isn’t it the open source community where you are often witness to truly agile projects out in the wild?
To me, I think it is a lesson in what happens when you have code that is hacked together, unclear, and difficult to maintain. Even worse, the original codebase was written for a language that has evolved VERY VERY quickly over time… PHP is now a different beast than it was when oscommerce2.2 was released (for java’ers, think of an app in java 1.3 in today’s world). And the fact it’s widely used compounds the problem.
Like any good software, good code often has users who are constantly in need of new features that need to be added. When dealing with legacy code, any new feature can be quite costly and often requires quite a bit of refactoring (or even complete rework) in order to be able to fit the new feature in nicely. Adding new features (while not breaking existing functionality) can be mind boggling sometimes… and if you don’t have any form of automated tests AT ALL (which oscommerce has none, to my knowledge) can be so scary that it deserves its own horror movie!
I’ve had my hand at working with legacy code, and the biggest lesson I have learned when it comes to rewrites is this: don’t. It is tempting… VERY tempting to just rewrite it, or rewrite whole sections. It’s tempting to do what oscommerce did with version 3.0: put together a big release plan and do some big bang releases with some complete rewrites. Don’t! While you’re spending time rewriting, planning, rewriting, etc… your competitors are releasing. And if they aren’t, your customers are growing impatient.
The approach I’ve found helpful is to simply release… add feature X, do a little cleaning up, and release. Complete feature Y, update the look and feel of the product management menu, and release. That way the features keep coming, customers keep getting satisfied, and the product evolves piece by piece in an iterative manner. But I’m off track… this isn’t a post about agile software development. 😉
To get back on track, this post is about the need for clean code. As software developers, we should always search out ways to improve the maintainability of our code if we want our product to thrive and grow… any deterrents to maintainability will impede others from improving it, and at worst will cause the code to become stale and often avoided. 😉
As a side note, although I have slammed OsCommerce for its code quality, I do have to acknowledge that for its time it was the best free shopping cart system out there… while others had to shell out thousands for crappy shopping carts with missing features, OsCommerce was there to offer those features not only better, but for free. The contributors and core developers did an EXCELLENT job meeting the needs at the time and producing what was honestly quite an awesome piece of software.
But, in the end, Legacy Code can come back to bite oneself in the a$$ if not properly controlled.