Code quality is one of the bricks of software quality. While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to rise. Automatic tools can be used to detect several types of problems including inconsistent style, long methods and repeated code.
Steve Hayes gave a presentation entitled "Code Quality For Java And Ruby" at the Agile2009 Conference held in Chicago, which gives InfoQ a good opportunity to review the tools available in the Ruby world:
- Roodi (Ruby Object Oriented Design Inferometer) - this parses your Ruby code and warns you about design issues from the list you configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks
- Reek - similar in concept to Roodi
- Saikuro - designed to check cyclomatic complexity
- Flog - created by Ryan Davis, this computes a score of your code: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score
- Simian - a similarity analyser, this can be used for duplication identification (you need a $99 license for commercial use)
- Flay - this is another free tool from Ryan Davis that finds structural similarities in code
Using all these tools can quickly become a pain, that's when metric_fu comes to the rescue. It includes all the mentioned tools (except Simian), and can easily generate a report about your application. It integrates easily with Rails and generates graphs over time.
Graph from Jakes Scruggs
You can follow Assaf Arkin's Guide to setting up Hudson for a Rails project with metric_fu support.
Community comments
Railscast #166 on metric_fu
by Sean Miller,
Excellent
by Marco Otte-Witte,
Re: Excellent
by Sebastien Auvray,
duplicate lines report
by Jean-Michel Garnier,
Railscast #166 on metric_fu
by Sean Miller,
Your message is awaiting moderation. Thank you for participating in the discussion.
Railscast #166 had Ryan Bates talking about metric_fu: railscasts.com/episodes/166-metric-fu
Excellent
by Marco Otte-Witte,
Your message is awaiting moderation. Thank you for participating in the discussion.
You might also be interested in excellent, a gem that combines many of the checks the above analysers provide and adds some checks that are specific to Ruby on Rails applications:
simplabs.github.com/excellent/
Re: Excellent
by Sebastien Auvray,
Your message is awaiting moderation. Thank you for participating in the discussion.
Hi Marco & Seam,
Thank you both for your links.
Marco, I also found out afterward this one for Rails: github.com/felipegiotto/Inotegration
duplicate lines report
by Jean-Michel Garnier,
Your message is awaiting moderation. Thank you for participating in the discussion.
Regarding dupplication, I wrote a gem which generate reports (HTML, Textmate, Netbeans, etc …) of identical duplicate lines, backed by java tool Simian.
wiki.github.com/garnierjm/dont_repeat_yourself