We're hiring!

From the monthly archives:

March 2008

Creating a new rails app shouldn’t be boring

by nicolas on March 24, 2008

For the impatient: grab the script here

You know, rails rocks for quickly prototyping an idea. And I like to think in code, so I tend to start a lot of apps to see if they lead somewhere (which they usually don’t, but that’s not why we are here). The problem with rails is that, even if it makes great points about don’t repeating yourself, and code generation, starting a new app is a tedious and boring process.

  • Update my rails svn checkout
  • Create the app from rails edge
  • Check it into source control
  • Emptying our routes file to get rid of the ugly defaults
  • Apply Dr. Nic’s GemsOnRails to freeze gems into the app.
  • Install rspec
  • Install haml
  • Any other gems or plugins you tend to use always (make-resourceful, sexy-scaffolds, etc)

So, a long while ago I hacked a quick shell script to do some of this for me, using svn and whatnot. I was, of course, not alone. We programmers are a bunch of lazy bastards, for sure :)

Yet times have changed. My script was getting old (I didn’t use haml or make_resourceful back in those days), and I’m using git now. So it was time for a rewrite.

Enter railify

It basically looks like this:

announcing "Fetching EDGE rails" do
  Dir.chdir(RAILS_SVN_CHECKOUT) { silent "svn update" }
end

announcing "Creating application layout" do
  silent "ruby #{RAILS_SVN_CHECKOUT}/railties/bin/rails #{app_name}"
end

Dir.chdir(app_name) do
  announcing "Setting up rails app" do
    silent "rm README"
    silent "rm public/index.html"
    silent "rm log/*.log"
    silent "rm public/images/rails.png"
    silent "cp config/database.{,sample.}yml"
    silent "rm -r test"
    File.open("config/routes.rb", "w") {|f| f << templates[:routes] }
  end

  announcing "Creating databases" do
    rake "db:create"
    rake "db:create", :rails_env => "test"
  end

  announcing "Configuring git repo" do
    silent "git init"
    File.open(".gitignore", "w") {|f| f << templates[:gitignore] }
    silent "touch {tmp,log}/.gitignore"
    git "Basic rails app structure"
  end

  announcing "Freezing rails" do
    braid "http://dev.rubyonrails.org/svn/rails/trunk", "vendor/rails"
  end

  announcing "Installing GemsOnrails" do
    silent "gemsonrails"
    git "Froze GemsOnRails plugin"
  end

  announcing "Installing haml" do
    silent "haml --rails ."
    rake "gems:freeze", :gem => "haml"
    git "Froze haml gem and plugin"
  end

  announcing "Installing RSpec" do
    braid "http://rspec.rubyforge.org/svn/trunk/rspec", "vendor/plugins/rspec"
    braid "http://rspec.rubyforge.org/svn/trunk/rspec_on_rails", "vendor/plugins/rspec_on_rails"
  end

  announcing "Generating RSpec base files" do
    silent "script/generate rspec"
    git "Added RSpec base files"
  end

  announcing "Installing make_resourceful" do
    braid "http://svn.hamptoncatlin.com/make_resourceful/trunk", "vendor/plugins/make_resourceful"
  end
end

Doesn’t it look pretty? :) You can check the full source at github.

So how do I make it work?

You need a few things in order for railify to run:

  • First and foremost, git and subversion
  • A checkout of the rails svn trunk (or a stable branch / tag, if you don’t want to run on the edge). The script’ll update this
    and generate the app from there.
  • The rails stack working (ruby, rubygems, a database of choice – I’m using sqlite) DUH!
  • Dr Nic’s GemsOnRails (sudo gem install gemsonrails)
  • haml (sudo gem install haml) *
  • braid, which is like piston for git, but much much more. There’re instructions on
    how to get it working here.
  • An operating system with a real user interface (aka, terminal). Linux, Mac or even CygWin should do, normal Win won’t.

It sounds like a lot, but probably you already have most of that working already.

But it doesn’t do…

The script is pretty simple to hack, so please do it! If there’s this other plugin you absolutely need to install, just add a block at the bottom and use the braid method to install it.

If you don’t want to update a local rails repo and instead just use the rails command, then you can just delete the ‘Fetching EDGE rails’ block, change the next one to run ‘rails #{app_name}’, and then use rake rails:freeze:gems in the ‘Freezing rails’ block.

Etc. You can fork the project at github and do whatever you want with it.

There’s still room for improvement

I have a few things in mind, like adding a reset.css and a barebones application.sass. A little error handling won’t hurt, either (for now it’s rm -rf !$ && !!). Any ideas?

Oh, and last, but not least, the script is released under a WTFP license


Nicolas works at CitrusByte, lives in Montevideo, Uruguay, uses vim and mate randomly and drinks too much caffeine. The stuff he does in mate usually ends up filled with :w.

{ 20 comments }

A while ago, Christian Sepulveda wrote an interesting post Why Rails will Reign Supreme. This is the latest variation on a theme that’s beginning to resound in the Rails community, and I can’t help but to disagree.

EDIT : Christian also has a follow-up post, Why Rails will Reign Supreme, revisited .

For the record, I am a big fan of both Ruby and Rails, and use them both in my daily work and personal projects. However, I cannot see them going mainstream anytime soon, or in Christian’s words, “Ruby/Rails can and will replace Java as the language and platform of choice for software development in the enterprise”.

Other worthy contenders have tried and failed1

Python has had a reasonable foray into the enterprise with Zope/Plone2, Twisted, and now Django and Turbogears. Heck, it’s one of Google’s “big four” languages for crying out loud. What better endorsement than that? But Python job numbers aren’t even close . Hmm what’s this? Rubyists haven’t even overtaken Pythonistas yet? What’s with all the hyperbole then? I know the growth chart shows Ruby growing at a phenomenal rate, but even then how many years before it can Eclipse Java?

Enterprise. Powerful language. Does not want.

So now Ruby, with funky belligerent offspring Rails in tow, is the next challenger. But it is too similar to Python. Simply put, Ruby the language is much too powerful for the mainstream — the same way Python is too powerful, the same way Lisp is too powerful. (This is using Paul Graham’s definition of power of course.)

The reason powerful languages fail is simple. Big enterprise does not want them. Remember, big enterprisey non-tech companies don’t like to hire superstar programmers (who typically prefer powerful languages). They prefer to have developers as low-cost interchangeable parts. It doesn’t matter if they have to hire 50 of them. Google around for some combination of the words ‘average java team size’ and see for yourself.

Java with design patterns3 scales a lot better for average programmers. Bear in mind I’m talking scalability with regards to team size, not with regards to deployment.

With Java, you lack a convenient way to use functions as first-class data . You can’t just open up a class and change default behavior like you can in Ruby. There is limited, if any, meta-programming. Roadblocks and safety nets abound. All these are reasons why many coders spurn Java, but they are the exact same reasons why it is so useful in big teams of mediocre coders. (You’re going to see me using terms like ‘mediocre coders’, ‘average programmers’, etc a lot. No slight against the top Java developers, but there are millions of Java developers and by definition most of them are average.)

Anyway, all this leads to senior developers being able to dump each programmer into a nice little cubbyhole coding a Facade/Adaptor/Observer where he isn’t likely to break anything. Half the naughty things generic programmer ID81732 can do should be caught during compile, and the rest that might get through, well there’s static analysis tools . With dynamic languages, there aren’t those safety nets4.

You can mention the wonderful Ruby/Rails ecosystem. Yes I know we have plug-ins and gems out the wazoo. The huge missing piece here is schools. Java has a veritable JavaCoderFactory of vocational schools and colleges churning out graduates year after year with students who know nothing but Java. In most schools, Ruby has to be learned outside of class, ie not mainstream. The battle has already been lost there, let alone 4 years later when those students are looking for jobs.

Christian concludes with “economics will dictate the needs of software and will establish the supremacy of Ruby and Rails”. I agree with the former. As for the latter, one of the chief concepts of economics is scarcity. And right now, good Ruby coders are scarce compared to their Java brethren. The scarcity of Rails coders compared to Java coders will raise the costs of developing with Rails (since with a limited supply Rails developers can charge more) to an equilibrium point with the cost of a Java team powered by a horde of mediocre code churners.

Another way of looking at this. Suppose one night DHH appeared to every CTO in the world in a vision and said “Tomorrow thou shalt start using Ruby and Rails”, and they all wake up and start looking for Ruby coders. What then? The sheer lack of programmers who know Ruby to fill that demand will mean other languages will have to be used. Mainstream? Pshhh.

I understand from Obie that a lot of big companies are starting to use Rails. That’s great news. But to truly go mainstream goes far beyond that. The companies listed all have (and need to have) a huge online presence. But going mainstream also means winning the hearts of non-tech companies who need bespoke applications. The kind of applications you never see or hear about. They don’t come with fancy gradients, social networking, or RESTful APIs. Yet million-dollar contracts are flying around to get them coded. In Java.

So what’s the big deal?

Why would Ruby/Rails developers want it to be mainstream anyway? There’s another term for becoming commonplace, and it’s called commoditization. Sure if Ruby becomes the new Java, then the early adopters suddenly have 5 years experience when everyone else has 2. That’s why this scenario is so appealing. However, mainstream also means hiring decisions will to be influenced more by non-tech people who don’t understand that 1 senior developer at 120k a year is more cost-productive than 3 junior developers at 30k per annum.

Paul Graham’s RailsConf 2006 Keynote Address, Power of the Marginal, was only two years ago. What’s happened since then? Why the obsession with being mainstream, when we’re having so much fun being on the outside?

Part of the appeal Ruby and Rails have is that they’re on the cutting edge. The moment there’s an “R2EE” out there will probably mark the beginning of the end for many. Time to look for a new language and framework. Scala on Sails. Javascript in Jail. Erlang with Extra-terrestrials. Whatever floats your boat.

PS: Once again, nothing personal against Christian Sepulveda - this essay is directed at anyone who thinks Ruby/Rails is taking over programming as we know it anytime soon - his just happens to be the most recent such post I have come across.


1 By ‘failed’ I mean that it still plays second fiddle to Java and C# in market adoption.

2 Yes I don’t think Zope/Plone then comes close to Rails now, but you have to consider the state of software frameworks available across all languages at that time.

3 For a hilarious look at Java, check out Steve Yegge’s Execution in the Kingdom of Nouns

4 Yes I know dynamic languages espouse testing, but good Java shops use tests too. Static analysis is something Ruby/Python et al cannot do.


CitrusByte developer Tim Goh aka ProgProg was previously a Python/Django hacker but is now a Ruby/Rails convert. He has been charged multiple times with method_missing abuse.

{ 18 comments }

Sass production woes in Rails

March 20, 2008

Rails 2.0+ introduced our team at CitrusByte to a Sass woe: our sass file would not regenerate. We would be able to regenerate it when ssh’ing into the site and starting the server in an environment other than production. Obviously not an ideal solution. So, what’s the fix?
Place the following in any ruby file in [...]

Read the full article →

What’s that? RSpec Haml Scaffolds? Yes, it is!

March 11, 2008

Some people use scaffolds, some people don’t. To those who do and happen to have their project taking advantage of Haml, probably understand the pain it is to go through all those lame rhtml files and convert them to Haml. Thus, a quick and dirty solution has arrived. Meet your master: “RSpec Haml Scaffolds”.
It’s hosted [...]

Read the full article →