So you’ve inherited an app. It is pretty well tested and doesn’t throw too many errors but the app is big enough that it is hard to tell what is going on most of the time. The original developers are long gone and you need to build new, mission critical features into the app but writing new code takes too long because all of the dead codealready in there.

You ever feel like that?

Half the problem is knowing where to start hacking at first.

As you probably guessed from the title; I suggest you start by killing zombie controllers. These controllers are still walking around but not doing anything and they are easy to find. Also, killing them off lets you use static analysis to find other methods on models, services, etc that could be killed off too.

A few methods to identify zombies

The manual way. Add an after_filter to the application controller that logs controllers and methods to a .log file then (after a while) check it and remove all methods (or whole controllers) that aren’t in that file.

New Relic. You can also find all the calls make to controllers and methods with New Relic and just delete any that aren’t there.

Coverband. Want to keep it simple? Add ‘gem coverband’ to your Gemfile and it will measure your code usage in production with a counter for each time a line of code is hit. It also works for more than controllers.

It is a good idea to use a combination of these approaches to make sure you aren’t killing off code that you might still be (unknowingly) using.

Got a better tool or idea that I missed? Drop it in the comments?

Join my email list By clicking submit, you agree to share your email address with the site owner and Mailchimp to receive marketing, updates, and other emails from the site owner. Use the unsubscribe link in those emails to opt out at any time. Processing… Success! You’re on the list. Whoops! There was an error and we couldn’t process your subscription. Please reload the page and try again.

How you can clean up some crazy controllers with form objects.