Posts

Showing posts with the label Metrics

metric_fu graphing, 1.9, and 'awesome' templates

Image
So there have been a bunch of metric_fu releases since I announced 1.0.0 on this here blog. It's now up to version 1.1.4 and we've added: Flog, Flay, Reek, Roodi, and Rcov now have graphs over time (thanks Édouard Brière ). Cool, dare we say 'Awesome,' templates for the metrics (thanks Nick Quaranto and Edouard Brière). Flog report now tracks average Flog score per method and the average of the worst 5% of your methods. MetricFu now works with Ruby 1.9.1 (thanks to Robert E. Rouse for his help). On to the pics: Homepage Google Group Github Repo Enjoy!

ORD Sessions and and introducing Flurn

I went to the first ever ORD session last night sponsored by Inventables and Google Chicago and worked on some metric_fu stuff. The idea of the ORD sessions is that there's a lot of open source developers in the Chicago (ORD is the O'Hare airport code) area so why not get them together to hack on some stuff. I'd say over 20 people showed up and had a great time. It didn't hurt that every one who came got an unlocked google phone as a free surprise gift. When they announced, earlier in the evening, that there would be a surprise we all thought: "Oh cool, I'll probably get a t-shirt or a squishy ball." So the phone sort of blew us away. As to metric_fu, Jeff from Inventables and I paired on a new meta metric called "Flurn." It's a combination of FLog and chURN and it tells you about files that not only are very complex but also change all the time. This is pretty bad because if the file is in constant flux and it's got a lot of ...

Iteration Zero

I spent the week doing an iteration zero for new project. The idea behind iteration zero is to get the development environment as automated as possible so developers can spend their time coding when the real development begins. So here's what we did: 1. Set up new git repository We use GitHub so that only took a few minutes. 2. Make new Rails app Again, just a few minutes 3. Set up geminstaller and basic gems (HAML etc.) Geminstaller installs gems needed by the project and makes sure they are there before starting the app. This functionality has been pulled into modern versions of Rails now, but I've found it a little wonky and I'm working with a former Pivotal Labs guy who just loves the Pivotal stuff (don't even get him started on Tracker vs Mingle ). 4. Set up developer tests. We looked into Shoulda , but ultimately went with RSpec (although we may use the Shoulda macros to test ActiveRecord) because most of the criticisms of RSpec are th...

Rails Conf 2009 Third Day of Sessions

Last night I chose quantity over quality and ate at a Brazilian steak house. Good times. Webrat: Rails Acceptance Testing Evolved Bryan Helmkamp (weplay) Bryan started out his presentation by handing out Tylenol for those who went out last night and Budwiser for those who didn't. The crowd was appreciative. Bryan show some typical Rails integration testing (simulating clicking through the app without opening up the browser) and compared it to the same test in Webrat. The difference between the integration test and the webrat enabled test was pretty dramatic. The Webrat test was much cleaner and easier to read. Webrat parses the returned html with Nokogiri (which he highly recommends) and so can do some pretty interesting stuff. click_link, fill_in, check (and uncheck), choose, select, attach_file, and click_button all have a simple syntax. Webrat automatically is checking for the success of the request so you don't have to assert success everywhere. It also verifies t...

MetricFu 1.0.0 is Out

What's new: Merged in Grant McInnes' work on creating yaml output for all metrics to aid harvesting by other tools Supporting Flog 2.1.0 Supporting Reek 1.0.0 Removed dependency on Rails Env for 3.months.ago (for churn report), now using chronic gem ("3 months ago"). Almost all code is out of Rakefiles now and so is more easily testable Metrics inherit from a refactored Generator now. New metrics generators just have to implement "emit", "analyze", "to_h" and inherit from Generator. They also must have a template. See the flay generator and template for a simple implementation. You now define the metrics you wish to run in the configuration and then run "metrics:all". No other metrics task is exposed by default. Full documentation, as always, is at: http://metric-fu.rubyforge.org/ Let the Google group ( http://groups.google.com/group/metric_fu ) know about any bugs you find.

Metric Fu Now Includes Flay, Roodi, and Reek

I released metric_fu 0.9.0 last night and just look at all the super cool changes since 0.8.0: Flay task finds duplication and structural similarities in your project Reek identifies common code smells Roodi finds mistakes and troublesome code A configuration class so you can configure like the big boys Standardization of the reports look and feel Increased RSpec coverage Source control type is auto-detected for Churn task Under the hood refactoring to make adding new metrics reports easy Of course it still does all the old stuff like 2 different types of complexity reports, code churn analysis, code coverage, and good old Rails stats. Set up a Cruise Control task to generate metrics reports every day and then you pinpoint the exact moment your project went to hell (or possibly avoid that fate -- your call). Check out the project home page at: http://metric-fu.rubyforge.org/ The best part about this whole thing is that almost everything added since release 0.8 has been added by the...

Metric Fu's Churn Now Supports Git

I just released version 0.8.0 of MetricFu. New in this release: Source Control Churn now supports Git (thanks to Erik St Martin) Flog Results are sorted by highest Flog Score Fix for a bunch of 'already initialized constant' warnings that metric_fu caused The flog reporter can now handle methods with digits in their name (thanks to Andy Gregorowicz) Internal Rake task now allows metric_fu to flog/churn itself To use the Churn task to find files that change a lot with Git, put this in your Rakefile: MetricFu::CHURN_OPTIONS = {:scm => :git} MetricFu is a Ruby Gem that gives you a fist full of code metrics. Find out more at the home page .

Different Ways of Installing Metric Fu

Something I didn't mention when I announced the re-launch of metric_fu as a gem is that now, because it's a gem, you have more options when installing it in your project. First option: Vendor Everything . Lots of people are big fans of unpacking gems into the vendor directory of their Rails project (or a similar folder in a non-Rails project) so that everyone who checks out the code gets the right version of the gem. You can then require it in your Rakefile like this: require 'vendor/gems/jscruggs-metric_fu-0.7.6/lib/metric_fu' However... Second option: Conditionally require the gem. When I announced metric_fu back in April, a lot of commentors bemoaned the fact that they would have to install something into their production code that wasn't really necessary for production. I don't really mind doing this as metric_fu does not modify any classes: It's mostly just a bunch of Rake tasks (and some report building code). However, I see their point. So if...

Metric Fu is Now a Gem

Image
I just released version 0.7.6 of metric_fu and there's all sorts of new stuff: First, MetricFu is now a Ruby gem on GitHub at: http://github.com/jscruggs/metric_fu Also, the Flog task can now flog any set of directories you like. Just put this into your Rakefile: MetricFu::DIRECTORIES_TO_FLOG = ['cms/app', 'cms/lib'] And, the Flog reports are much nicer: The Flog report generator now looks at a MD5 hash of the files its examining to determine if they files need to be re-Flogged -- which saves time. The Saikuro report generator can also look at custom directories like so: MetricFu::SAIKURO_OPTIONS = {"--input_directory" => '"cms/app | cms/lib"'} MetricFu started its life as a Rails Plugin, but I'm trying to turn it into a flexible gem that can be used in any Ruby application (but still have defaults that enable easy use in a Rails project). Eventually I'd like to create something that could tell you about methods that have hig...

I'll be Presenting at Windy City Rails

If you're going to be in the Chicago area on or about Saturday, September 20th, you can see me give my "Using Metrics to take a Hard Look at Your Code" talk at the Windy City Rails Conference . David Heinemeier Hansson, David Chelimsky, and Noel Rappin have been announced as speakers and I'll be joining them for a interesting day of Rails related goodness. Here's the abstract: It's an interesting fact of human nature that you can't do something every day and not secretly suspect that you're good at it. Which goes a long way toward explaining why everyone thinks they write fine code. To combat this self-delusion you can use metrics to take a hard look at your application. This talk will discuss the ways in which you can measure how good your Rails project really is. And how to fix the bad parts. Using a daily metrics build (run every day by CruiseControl.rb) you can compile a 'hit-list' of the worst methods in your application. Then your team ...

What's a Good Flog Score?

I've been using Flog to measure the complexity of my Ruby code and I was wondering how others interpret Flog numbers. I'll go first with my opinions: Score of Means 0-10 Awesome 11-20 Good enough 21-40 Might need refactoring 41-60 Possible to justify 61-100 Danger 100-200 Whoop, whoop, whoop 200 + Someone please think of the children (note: these are scores for an individual method) The 20 - 60 range is interesting to me. Sometimes the complexity of what you're doing will justify the score and other times the method is in desperate need of refactoring. The highest Flog score I've seen in the wild was in the 300's. What's you're personal high and what do you think of my rankings? In other news, I've redesigned the look of my blog so if you only see my post through a reader you might want to stop on by, take a look, and tell me what you think.

Presenting at Lone Star Ruby Conf

Word on the street is that Lone Star Ruby Conf was one of the best regional conferences last year, so I'm pretty excited to be presenting at the 2008 edition. It's happening Sept 4-6th in Austin, TX and speakers include: Matz, Evan Phoenix, Jim Weirich, The Rails Envy Guys, and too many other luminaries to name. I'll be giving a talk entitled " Using Metrics to Take a Hard Look at Your Code " which is a distilation of my thinking over the past year about how to use numbers not as a hammer with which to beat people, but as a tool to improve your code. Registration just opened up today, but space is limited so go sign up soon.

Metric_fu Now Measures Churn

Image
Sometimes a class does too much. It's used everywhere, does everything, knows all about the nasty internals of all the other classes, and every time you change anything in the application it has to change. Or maybe you have a class that everyone loves to refactor because it's so bad. One developer changes it to be better, then another changes it to be a different kind of better, and this keeps happening without it ever getting any easier to use. There's a lot of bad reasons why a class might change all the time so I added a churn report capability to metric_fu version 0.6.0. Now you can use metric_fu to create a report like this: By issuing this command: rake metrics:churn And use the results to find classes that might have problems. It uses 'svn log' to create this report so currently you need to be using subversion. (If anyone out there want to contribute some code to get it working with git, lemme know.) The default is to start counting changes fro...

Dead Simple Rails Metrics with metric_fu

Image
Every time I create a new rails project I usually put off writing tasks to analyze the code's quality 'cause it takes time and time is, you know, finite. So I've decided to extract some code into a rails plugin which I call metric_fu. It's a bunch of rake tasks that produce reports on code coverage (using Rcov ), cyclomatic complexity (using Saikuro ), flog scores (using Flog ), and rails stats (using 'rake stats'). It knows if it's being run inside a CruiseControl.rb build and puts the output in the Custom Build Artifacts folder so when you view a build you see this: The coverage report is your standard rcov report: Flog output is thrown into an html file: At the end metric_fu calculates the average flog score per method: You might want to check out my previous posts on what to do with a Flog report: The Method Hit List and When You Should Ignore Metrics Saikuro's output is the same as always: (I changed the warning and error levels for this pic -...

When You Should Ignore Metrics

Our team has been doing a bang up job of reducing our complexity through our hit list (All of our methods are ranked by Flog score and we spend some part of every iteration picking the worst methods and trying to refactor them.). But sometimes we run into a situation where we prefer a high Flog score to a low one. For instance, this bit 'o code: def is_something?(x, y) x.foo == y.foo && x.bar == y.bar && x.blah == y.blah && # and 10 more lines of the same end which had a Flog score in the 60s. We could have changed it to this: def is_something?(x, y) ["foo", "bar", "blah", # and so on ].inject(true) do | a, b | a && x.send(b) == y.send(b) end end Which gave a us a much lower score. However that first method is crazy simple. Merely glance at it and you know what it's doing. The 'less complex' method? Even an experienced ruby dev would need a moment or two. As for a new dev... I can remem...

The Method Hit List

In a previous post I talked about how my team has a daily metrics build that reports on our code quality. One of the things we measure is the Flog score of our methods (Flog is a ruby program that evaluates the complexity of your methods). We have a standing developer task to look at the top five worst methods in our application and reduce their complexity. Every iteration we try to spend some time looking at a few developer tasks, which are things that don't provide any direct business value but do make our code better, automate some manual process, or fix some technical problem not tied to a bug. Yesterday Chirdeep and I refactored the worst method in our app and while it wasn't easy it produced a number of benefits: First, about halfway though the refactoring we came upon some twisted logic that seemed as if it could never evaluate to false. After pulling in Ali for some consultation, we realized that indeed it would always be true and therefore was a bug. We fixed i...

Metrics for Rails

Everyone thinks they write good code -- it's just part of human nature. You can't do something every day and not secretly suspect that you're good at it. Self-delusion is a powerful thing so you need to use metrics to take a hard look at your code. On my current project, we've just added a daily metrics build (run every day at midnight by CruiseControl.rb ) that takes a look at our code in three ways: Code coverage with Rcov Cyclomatic complexity with Saikuro And um..., Flogging with Flog Rcov is a code coverage tool that can be used with Rails Rcov to add a bunch of rake tasks to your build so you can figure out which lines of code are run by your tests... and which are not. Saikuro computes cyclomatic complexity which "measures the number of linearly independent paths through a program's source code." Methods with more paths are harder to understand/debug/modify. And Flog is cyclomatic complexity with an attitude. It scores ruby methods with an ...