Archive for July, 2007

h1

Rails Wanted Dead or Alive $2.500.000!

July 10, 2007

Wanted Rails

Rails success is not debatable. But this was not an easy battle (and still isn’t) and some projects are trying to keep the ewes into the JEE garden.

Rails SLOC 2004-2007

This represents the SLOC (Source Lines Of Code) of Rails since it was born 3 years ago.
What to say about this? Basically you can’t say much about SLOC (see the SLOC part of a previous post)… Except that the progress is regular (which can be explained by the fact that it is maintained by a company in contrast to open source projects which might have an important growing community of commiters)
Now sloccount gives us a summary:

Total Physical Source Lines of Code (SLOC) = 74,385 (100% Ruby)
Development Effort Estimate, Person-Years (Person-Months) = 18.45 (221.45)
(Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
Schedule Estimate, Years (Months) = 1.62 (19.46)
(Basic COCOMO model, Months = 2.5 * (person-months**0.38))
Estimated Average Number of Developers (Effort/Schedule) = 11.38
Total Estimated Cost to Develop = $ 2,492,879
(average salary = $56,286/year, overhead = 2.40)

So the reward for Rails is $2,492,879!
This is based on 2004 salary…

Now if you want to have some fun and get some stats from your favourite svn repository, go get Ruby, go get Gruff, go get sloccount, go get a Beer, and relax!
Sorry for the format but WordPress really doesn’t help me…
# railssloccount.rb
# July 10, 2007

require 'date'
require 'rubygems'
require 'gruff'

DIR_DOWNLOAD = '/home/username/railssloccount/'
STEP = 15
FIRST_DATE = '2004-11-29'
GRAPH_SIZE = 400
GRAPH_HORIZONTAL_AXIS_SPACE = 16
axis = {}
datas = []
index = 0

puts "svn checkout --revision {#{FIRST_DATE}} \
\"hxxp://dev.rubyonrails.org/svn/rails/trunk\" \
#{DIR_DOWNLOAD}trunk"


`svn checkout --revision {#{FIRST_DATE}} \
\"hxxp://dev.rubyonrails.org/svn/rails/trunk\" \
#{DIR_DOWNLOAD}trunk`


(Date.parse(FIRST_DATE)..Date.today).step(STEP) do |date|
axis[index] = date.to_s \
if
index % GRAPH_HORIZONTAL_AXIS_SPACE == 0
index += 1
puts "svn update --revision {#{date}} \
\"hxxp://dev.rubyonrails.org/svn/rails/trunk\" \
#{DIR_DOWNLOAD}trunk"

`svn update --revision {#{date}} \
\"hxxp://dev.rubyonrails.org/svn/rails/trunk\" \
#{DIR_DOWNLOAD}trunk`

puts "sloccount #{DIR_DOWNLOAD}trunk"
result_cmd = `sloccount #{DIR_DOWNLOAD}trunk`
File.open("#{DIR_DOWNLOAD}sloccount_#{date}.txt", "w") { |f|
f << result_cmd
}
result = result_cmd[/ruby:\s*(\d+)/].gsub(/ruby:\s*/, '').to_i
puts "Date: #{date} - SLOC: #{result}"
datas << result
end

axis[index-1] = last_date.to_s

g = Gruff::Line.new(GRAPH_SIZE)
g.data('Rails SLOC', datas)
g.labels = axis
g.minimum_value = 0
g.title = 'Rails SLOC'
g.write("rails_sloc_#{STEP.to_s}day_#{GRAPH_SIZE.to_s}.png")

Advertisements
h1

A Controller DSL to Complement MVC

July 3, 2007

Bruce Williams has been working on the view pattern over the past years; Notably the problems it raises: heaviness, conciseness, complexity, depending on the solution you choose. The presentation he gave at RailsConf, When “V” is for “Vexing”, introduced a Controller DSL: folder_for. Bruce gave an exhaustive use case of it on his blog.
Starting from a simple example that will need Folder interfaces, he naturally chose to use a DSL: folder_for.

 class CarsController < ApplicationController

    # ...
    folder_for :show do
      tab "General Information" do
        @score = current_user.score_for_car(@car)
      end
      tab "History"
      tab "Photos"
    end
    # ...

 end

Bruce uses convention over the use of one view template to render each selected tab partial (cars/show.html.erb). His views will be structured this way then:

 cars/
    show.html.erb
    show/
      _general_information.html.erb
      _history.html.erb
      _photos.html.erb

Bruce doesn’t only bring a new plugin which is more like a sample code; But he showed that a hundred lines of code was enough to accomplish his task demonstrating that a DSL can be deployed effectively with Ruby. The code is cleaner even if breaking some rules:

There are likely several of you reading this that are disturbed to see a folder reference within a controller, as this amounts to some level of MVC “separation of concerns” blasphemy in your very strict, very well-worn code rulebook.

I’m here to tell you it’s okay, and you’ll recover in time.

Let’s keep in mind here that the MVC separation of concerns, while a great rule of thumb, is just that … it is not an ivory tower to be left unassailed in times of dire need. At times, it makes sense to allow abstractions to cross these boundaries for the sake of reducing our own overhead, and in the cause of developing your own app-wide domain specific language—something, that in my book, is the principal sign of a good Rails developer (for what it’s worth).