Cleaning Up Bad Code Via Dependency Graphs

Nicolas Seriot shares:

As developers, we all love clean code, but the fact is that most of the time we’re dealing with bad code. It may be recent or legacy code, written by ourselves or by other developers. We can recognize bad code because code smells. In other words, some heuristics raise questions about code quality. Among thoses we can name dead code…and tight coupling.

Nicolas goes on to explain how it is that one can achieve loose coupling, first by understanding the existing coupling, which is where his github project comes into play.

Here’s how it works:

I wrote, a Python script which extracts imports from Objective-C source code. The output can then be displayed in GraphViz or OmniGraffle. You can then see an oriented graph of dependencies between classes.

And a finished graph: