Perlessence
Cleaning up code
One of the problems in a company that started with a bunch of junior developers is legacy code. As the devs have grown more skilled and knowledgeable, the code has been refactored or scrapped and rewritten from scratch. Often times, the old version was left behind; usually it's because people forgot to remove the old stuff, but sometimes there are still dependencies that are outside the scope of the new code or the belief that the old code should be kept "just in case" or for a rollback. I try to devote one day a week to cleaning up the codebase. I just finished removing a legacy rails-like framework that used to power Gaia's profile system and was left behind when profiles were moved to our standard MVC framework.
Cleaning up code is usually a thankless job, but I find it satisfying, especially when I get to delete a lot of files. Why bother cleaning up old code? The biggest reason I've found is so when we make changes to one component, we don't have to worry about what is and isn't active that might break. It also helps when grepping through the codebase for something, that only current files will match. Given that we're using a couple different systems, some of which can't talk to each other, getting all our code into one framework would help immensely in code reuse and speed up development.
I start by using my knowledge of the codebase and what is/isn't being used to identify potential areas for cleanup. Once I find an area, I read through the relevant code and identify the dependencies. In PHP, this means anything from other PHP files and HTML dependencies such as image/CSS/JS files. The tricky part comes when some files are dynamically included (see snippet below).
include_once DIR_CLASSES . $myclass . '.class.php';
After getting a feel for how spaghetti'd the code is, I start grepping. I take one of the dependencies, see where it's called in the codebase and if nowhere except the code I'm removing, I know it's safe to remove the file. Sometimes it's still called in other areas that are still in use. If so, I either leave the file as is or move it to a new location relevant to the remaining area that's calling it and change all references. I test the site at regular intervals to ensure everything is working as designed. Then QA does another runthrough before it's okayed to push live.
Once I'm done removing obsolete code, it'll be time to hit up the images, CSS, and JS and to organize those files. And after that, I'd like to convert repeated code into reusable models and refactor the relevant apps. I estimate I have about a year's worth of work :D