This is a frequently asked topic... And I have read through many posts, articles and am about to read the book Working Effectively with Legacy Code
, but before that and mainly because it will take more than a couple days for book to arrive, and I would like to keep my sanity in check, here's the question:
I am looking at not-that-old (1-2 years) code by a company I recently joined, and I have found so many bad practices in there that it's almost heart breaking...
Massive code duplication, global variables (which are inconsistently used), and things like using a factory class to instantiate various objects that extend a parent object... and then calling methods that don't exist in the parent, but are defined in all the subclasses...
The code works... It's rigorously QAed and bugs are at a minimum, which is fine... but I cringe so much looking at the code...
I recently asked my boss if I could refactor the entire codebase, he asked how I would be able to guarantee the changes will not break anything, I asked we could invest some time to create real unit tests, as their so called unit tests are actually end-to-end tests, so we have to trace the debug log very time something breaks. He said we don't have enough time to create the unit tests (actually the code isn't very unit testable, since there is so much tightly couple code... and I would've had to pretty much re-write most of the classes), so in effect I couldn't even do minor changes to code if it isn't listed as a bug in the issue tracker...
What I'm doing right now is alot of copy and pasting... then fine tuning that since the logic isn't exactly the same...
What can I do? :/
Sorry I think I'm just venting here, and there is nothing I can do in the short/medium term... sigh