The Code
I have high-business-value daily-used-by-customer software that is written in PHP and spans approximately 600K lines of code.
Customer for a long time needs, wants, and demands new features and functionality. The time to have it done is yesterday. So, just write the new features and implement new functionality and deliver it to the customer, yes? Well, no, here are some problems that have been causing considerable pain to current developers:
Existing code-base is ... a big ball of mud.
Notable problems:
- code is hairy - a single feature permeates everything, tracing code is a pain, and adding a feature may potentially impact everything else
- there are no tests
- mix of procedural and object oriented code ridden in bad programming practices
- files reaching 6000-lines of HTML, CSS, PHP, SQL, jQuery, JavaScript, comments
- complete disregard/non-existence of MVC/separation-of-concerns pattern. Code is intermixed together
- some business logic depends on volatile things that have no relation to the code (like database metadata)
- hardcoded values, paths, and lack of configurability contribute to lack of security of current architecture
- large repeated blocks of essentially the same code contribute to similar features working slightly differently. Updating one does not update the other
- code is slow, lack of documentation., etc, etc. quite a few other things can be done better
It works...
The good thing is that it works... The functionality that's there, is reasonably worked-out for actual business cases, but ... going forwards is painful.
The Problem
It is easier now (and faster) to add a new feature using existing code style, mostly using cut-n-paste-n-modify approach, thus perpetuating the badness, than it is to do rewrites of this thing using currently existing modern best practices.
Solution?
There is a talk about rewriting the whole thing using one of the currently-leading frameworks (i.e. ZF2), but in doing so it means ignoring customer demands, taking a long time to build the software, and essentially creating new software (version 0.0.1) for the customer, with all the new-software bugs and lack of mature-software feel and functionality.
Another thought is to do some incremental development. i.e. When a new feature comes about, write it using a new approach. This is currently failing for the reason stated under "The Problem" title above.
Yet another idea is to do some slow refactoring of existing codebase... It might work in cleaning up things like MVC and a host of other things, and it will take a long time, and it will essentially feel like unraveling a messed up tightly-wound knotted ball of yarn. But doing this will not address things like unit testing, dependency injection, modern framework principles, and so on.
So, in the end, new features are coming, code is being added, and the existing codebase is not getting any better. What might you suggest to do in this case?