Wednesday, February 07, 2007

Ruby Rails Cyclomatic Complexity analysis

Cyclomatic Complexity analysis is very useful in figuring out where to refactor code; what parts of the code need most clearing up, what code should be broken into new classes and methods etc.
Analyzing complexity of ruby applications is very easy with the cool app by Zev Blut, Saikuro, it uses ruby-lex to analyze the complexity, mainly by counting IF/AND etc statements per method.

I ran it for my ajax stock trading rails demo app, nexavibes, interestinly due to the rails MVC architecture and other rails default use of lot of patterns without having spent much effort on this rails application in refactoring, it comes out pretty well by these metrics. Since this app includes lot of javascript code that I wrote from scratch, that javascript would have some higher complexity numbers, however saikuro only analyzes ruby code for now.
If you know of a free open source complexity analysis tool for javascipt or C/C++, leave a comment.
But, anyway, here's the results that I got:

http://nexavibes.maanpaa.com/saikuro/index_cyclo.html
http://nexavibes.maanpaa.com/saikuro/index_token.html