Aug 2
Today: 02-Aug-2010: Global Domination
I think today I have seen one of the most poorly written bits of code I have ever seen. I have so far counted over 50 different global variables interspersed throughout the code occurring three levels deep into the application (yes, that’s three levels of includes before the global was set, scary!) even though they were being used at the root level.
This spaghetti code is amazing in its complexity and a distinct lack of maintainability. I’m surprised that the code has hung together so well as at the moment I’ve managed to combine around 21 different global variables into a single configuration class which should make things clearer. I’ve spent the day pouring over the code cleaning things up to form a more coherent base. Whilst I’ve been cleaning things I’ve been trying to work out where things are being used. Already in one file I found five functions sitting around that aren’t being used anywhere. The most depressing thing is that since the code wasn’t version controlled there are legacy files with “old” or “2” suffixed and functions with “old” in their name – or worst of all combinations of those options: “old2”. I even found a function that never would have returned a sane value.
Suffice to say the entire system lacks at form of standardised testing which makes refactoring even harder. Given the intermixing of HTML outputting all over the place I think it would be hard to quickly put in a unit testing framework to ensure that the system behaves sanely.
Whilst it immensely frustrates me that I have to deal with it, I’m hopeful that I can start cleaning it up and improving the overall quality. Shifting functions around and centralising items in ways that makes sense as well as clearing up old cruft and the elimination of the immense plague of global variables that this application has. I thought Drupal was horrible with all of it’s global variables (it was seriously the most global’s I’d seen before at around 20 of them) but this one at over 50 and counting takes the cake – it really is global domination.
No commentsNo Comments
Leave a comment