Java kicks Ruby in the what now?
When I first read the Java Kicks Ruby on Rails in the Butt article by Javier Paniza, I brushed it aside as something from the time when Rails was just getting traction and people using related, established technologies started feeling threatened.
I then noticed the date - turns out the article is only a few days old! Color me confused, could that article really have been written in 2009? I thought we had left the FUD-spreading behind us.
In an effort to educate Javier - and hopefully others - I decided to rewrite the Rails part of his article the way he would have written it had he had more knowledge and experience with Rails.
Models
First order of business when creating a Rails application is to generate the basic structure. This sets up our directory structure, configuration file, and all the other goodness that makes it easy to find ones way around a Rails project:
$ rails cookbook2
create
create app/controllers
...
$ cd cookbook2
We need to store recipes and categories, so let’s create two models with their database tables. Since Javier doesn’t like passive code generation, I’ll try to limit that in this tutorial, hence I am using the model generator rather than the scaffold generator for this:
$ ./script/generate model Recipe category_id:integer title:string description:string instructions:text
$ ./script/generate model Category name:string
$ rake db:migrate
This creates our models and the relevant database tables with the specified fields. No SQL is required, no need to mess around in more or less usable database GUIs. We’re also getting the inklings of an eventual test suite created for us.
Controllers
At this point we need to create some controllers we can access through a browser. The easiest way - at least the way that’s easiest to describe in words - is to simply use the controller generator twice:
$ ./script/generate controller recipes
$ ./script/generate controller categories
This creates two controllers of 2 lines each - obviously trivial to do by hand. I’ll leave that as an exercise for the code generation wary reader.
The not so secret ingredient
It’s time to install the secret ingredient, which is what Javier really wanted to be comparing his project with. Streamlined is a framework (seems everything is these days?) that “… allows you to quickly generate useful user interfaces, declaratively”:
$ ./script/plugin install git://github.com/relevance/streamlined.git
In order to hook Streamlined properly into our application, a few files need to changed (we’re actually writing code now, for the first time). First, add one line to the Application Controller:
# app/controllers/application_controller.rb:
class ApplicationController < ActionController::Base
...
layout 'streamlined'
...
end
Both the controllers we created before needs a single line added, increasing their line count by 50%!
# app/controllers/categories_controller.rb:
class CategoriesController < ApplicationController
acts_as_streamlined
end
# app/controllers/recipes_controller.rb:
class RecipesController < ApplicationController
acts_as_streamlined
end
The next step is optional, and you can skip it if you like navigating by changing the URL in the address bar of your browser. If you prefer navigation you can click on, add a single method to the ApplicationHelper:
# app/helpers/application_helper.rb:
module ApplicationHelper
def streamlined_side_menus
[
['Recipes', {:controller => 'recipes'}],
['Categories', {:controller => 'categories'}]
]
end
end
Time to start our application and see how it looks
$ ./script/server

Wow, look at that. Note that you can filter the entries, sort the columns, export to a variety of formats, and pagination is built in. Looks almost production ready, doesn’t it?
Looking back, it looks like I wrote a massive 9 lines of code (3 if you skipped the optional step, 13 if you created the two controllers manually). No unused application code has been generated.
Little work, polished result indeed.
Adding a relationship
Let’s round this article off by refuting yet another false claim in Javiers article. To create a relationship - or association, as we call it in the Rails world - all you need to do is add a single line to your model:
# app/models/recipe.rb:
class Recipe < ActiveRecord::Base
belongs_to :category
end

Now refresh the page for creating a new recipe. Voila, there’s a dropdown box for assigned categories to recipes. There is no need to write any HTML, restart the server, or recompile anything for that matter.
Conclusion
Interestingly enough, while Javiers article is filled with inaccuracies and is based on his lack of knowledge of Rails and its ecosystem, I don’t particularly disagree with his conclusion.
Rails does use passive code generation, and yes, if you want to extend or refine the generated code you have to actually edit it. You know, that sounds an awful lot like programming to me.
That said, I seriously disagree with the idea that productivity can be measured using contrived examples, and that a technology can be evaluated based on cursory knowledge gained from a 2 year old tutorial.
Comments
Morgan Roderick May 20, 2009
Jakob, thank you for setting it straight.
I read Javiers post the other day as well, and was wondering why he had not gotten a Rails guy to clear up inaccuracies before posting it.
Paulo Cesar May 22, 2009
Great article! It's indeed very stupid to make comparisons without knowing nothing about the subject..
I always create my own controllers/views, but this Streamlined seems useful for some cases, thanks for the tip!
Jim Connell May 22, 2009
I was hoping somebody would write this exact post. Thank you. Poorly coded Rails app aside, his article doesn't discuss what would happen should you want to get away of that 1999-looking administration interface (as you might for any real-world client). I don't know myself, but I would guess it wouldn't be easy to do that in OpenXava.
A Java Guy May 22, 2009
Hi,
To me it doesn't matter whether you express something in 10 lines or 20 lines of code.
Ruby might do some thing in 1 line of code where Java requires 10 lines.
What really matters is the maintainability of the code, refactoring support, scalability of the platform, multiple vendor support, availability of programmers, IDEs, frameworks etc.
Do you think Ruby can beat Java on this ?
Ariel Arjona May 22, 2009
what I find amusing is how CRUD has become synonymous with 'web application' these days.
-- "My CRUD can beat up your CRUD!"
-- "nu huh!"
-- "does too!"
GR May 22, 2009
Please note that the author of the other article is also the creator/maintainer of the OpenXava framework project so no one should come to it thinking that it is anything more than marketing of his framework.
Secondly, Streamlined might not be the best example to build from. Its been in Release 1.0RC3 status for more than a year, and saw its last commit in GitHub in September 2008. I try not to rely on stagnant code.
http://github.com/relevance/streamlined/commits/master
Your point is well taken though. The other author was biased, and (purposely) ignorant of how Rails works.
Cheers.
A Ruby Guy May 22, 2009
nice article!
@Java guy:
1. maintainability of the code: absolutly
2. refactoring support: absolutly
3. scalability of the platform: what does mean "scalability" to you?
4. multiple vendor support: not sure
5. availability of programmers: there are more java programmers
6: IDEs: there are more java ides (an editor is enough though)
7. frameworks: not sure, there are enough frameworks for ruby IMHO.
anyway, you can use Java libraries (and JVM) via JRuby, it works pretty well.
Other Java Guy May 22, 2009
Rails is a nice plataform, as PHP.
But when you need real enterprise application, no one can beat Java.
Am I wrong or twitter is in rails? They were having serius problems in rails scalability and are junping of RoR.
So, about scalability: java is better
bwtaylor May 22, 2009
I don't think there is any question that RoR has accumulated a "bag of tricks" that creates a very fast development cycle. The question is which of these cannot be adopted by other languages (eg django, grails, etc...) vs what positives do you give up by moving to ruby.
Here's what I think you give up if you use Ruby:
- runtime performance
- a large base of libraries
- tooling
So if I like configuration over convention, scaffolding generation, a highly structured MVC approach, and DSLs for things like ORM, then I have a choice: I can use rails and hope the ruby community bolts on the things that are missing and accept that some never will, or I can look to java, python, scala, or other directions and try to figure out how to bolt on a rails inspired approach to them. I think rails peaked in about 2006 and that both grails and django have already achieved technical parity with it in the areas listed above and so effectively neutralize its advantages.
Another Java Guy May 22, 2009
@Other Java Guy
you are wrong about twitter. Please get the facts before spreading FUD and BS.
tooling May 22, 2009
bwtaylor you speak like a python guy, FYI ruby is already faster (hello ruby1.9) than python so either your very 1st point(runtime performance) or your argument is invalid.
"- a large base of libraries" seems invalid to me, can you point a library missing for ruby? in fact, people built lots of (large) sites with PHP
"tooling" whatever.
so, why do you hate ruby?
tooling May 22, 2009
oops, my point about PHP was that ruby has more (thousands!) libraries than PHP.
Other Java Guy May 22, 2009
@Another Java Guy Realy?
Sorry, my bad. But this confused me http://www.techcrunch.com/2008/05/01/twitter-said-to-be-abandoning-ruby-on-rails/
Is this right? Was twitter in RoR but not anymore? (the article date is 05/01/2008)
Another Java Guy May 22, 2009
@Other Java Guy: twitter is still using RoR, techcrunch love to create false stories, and people love to spread their BS. (specially python people ;))
the problem with twitter was the backend (not rails!), first they were using one database for the whole app! (crazy), 2nd they were creating records inside rails' controllers (wrong!!), after that they moved to a very slow backend (starling iirc) and now they built a new backend in scala which seems to work fine.
Another problem is MySQL which doesn't scale well in these kind of environments.
Other Java Guy May 22, 2009
@Another Java Guy
Thx for your explanation.
But I still believe that java scalability is better
Yet Another Java Guy May 22, 2009
@Another Java Guy: Why dont you read the source, where Blaine Cook and Alex Payne explain to David Heinemeier Hansson why Rails sux http://tinyurl.com/twitter-rails-trouble
Alex Payne: The solutions to this are caching the hell out of everything and setting up multiple read-only slave databases, neither of which are quick fixes to implement. So it
A Ruby Guy May 22, 2009
again, what does mean "scalability" ?
Other Java Guy May 22, 2009
@A Ruby Guy
http://en.wikipedia.org/wiki/Scalability
Another Java Guy May 22, 2009
@Yet Another Java Guy: sigh, did you actually read that blogpost? that's PRETTY old, that was the RESPONSE from DHH. I explained that they were using ONE database for the whole application.
from the blogpost:
"In this case, it seems that Twitter requires more sophisticated ways of talking to many databases at the same time. Alex puts it a little black and white with "...there
Another Java Guy May 22, 2009
@Other Java Guy: re sigh, did you actually read that article on wikipedia? Languages(ruby, java, python or whatever) DO NOT scale. Frameworks(struts, openxava, rails, merb, django,...) DO NOT scale.
Other Java Guy May 22, 2009
Ok, java, as language, do not scale and so his frameworks. But java applications servers (like jboss, borland enterprise server, etc) do very well.
And when I said java scales better than Rails, I was talking about the whole platform
Jonathan May 22, 2009
Yes you Java guys are right. Java is better. STICK to it (and leave us with our poor!
mwah hahaha! MOAH HAHAHAHA!
Yet Another Java Guy May 22, 2009
@Another Java Guy: Well, how about you read not just the post itself http://tinyurl.com/twitter-rails-trouble where David Heinemeier Hansson tries to shift responsibility from Rails weaknesses to Twitter, but responses as well, where he is being repeatedly reminded that you cant fix technology problem with business attitude (throw more servers, databases, cluster everything, Rails is beautiful)
As they say: "Programmer productivity is a wonderful thing, but if your ruby box can only support a couple hundred simultaneous users (vs. a Java machine that can support a few thousand), you're buying 10x as many servers. When you get to any serious scale, that translates into many hundreds of thousands of dollars - several years of programmer salaries. That doesn't even include the management headache of dealing with all those machines."
Yet Another Java Guy May 22, 2009
@Jonathan: You know, after reading "Rails Is A Ghetto" written by Zed Shaw creator of Mongrel, I'm not surprised to see or hear hysterical laughs from Rails people, and I prefer to stay as far as possible from "Rails Community"
http://tinyurl.com/rails-is-a-ghetto
Zed Shaw: "I
Jim May 22, 2009
The original article was a grasping effort to get some traction for a framework few people have heard of and fewer still will use.
As a guy who still does webapps in Java, RoR changed the world. It was like Roger Bannister, breaking the 4 minute mile. Everyone had assumed that coding webapps had to suck. And then Rails showed us that they didn't. We had thought that the sucking wasn't caused the ecosystem and heavyweight tendencies of Struts and Enterprise frameworks.
Rails changed everything. It doesn't quite look like it's the Java killer yet. Java has some advantages. There are still plenty of reasons to choose Java over Rails, but the original didn't highlight them.
rubish May 23, 2009
Yet Another Java Guy, man you are so wrong, most ruby performance problems are already fixed. And you as JAVA developer can't talk about hardware, Java eats 10x more hardware than ruby, so please shut up...
oh and Zed removed his article for some reason..., could you please stop your ad-hominem attacks? thanks.
to conclude, can you all stop pointing articles from 4+ years ago? for sure you could find an article from when Java were SLOW as hell
http://www.slideshare.net/mattetti/merb-for-the-enterprise-presentation
A Ruby Guy May 23, 2009
"you
Yet Another Java Guy May 23, 2009
@rubish: Your nickname represent quality of information you produce, which is probably norm in your "Community" from what I hear. As a MS in CS, I DO care and talk about hardware limitations and requirements for Java apps carefully, compare that to "just throw dozen more boxes at it" Rails fan-boy.
@A Ruby Guy: See, Zed is right again, if you people, would have had formal education, you would have known that compiled language much faster than interpreted one (same generation)
And of course, you people try to mix and divert attention by interchanging Ruby - Rails (Very Nice Language - Sh.tty Framework, in case you dont know)
I've made my case, there are lots of real_world benchmarks (not just silly CRUDs) that explain why nobody takes Rails seriously. Keep living in your dreams boys, one day you will grow up.
rubish May 23, 2009
@Yet Another Java Guy: we will probably talk when you stop personal attacks. And please (at least) post the source of what you are claiming.
"Your nickname represent quality.."
"which is probably norm in your
rubish May 23, 2009
http://en.wikipedia.org/wiki/Ad_hominem
Java fans May 23, 2009
To Ruby developers:
Ruby can't beat Java..that is the fact. We can't say that ruby is a language because it is not a language but just a script. However, ruby is faster and easy but not suitable for medium to large application.
bertin May 26, 2009
I'll give ruby a try, looks awesome
assman May 30, 2009
"See, Zed is right again, if you people, would have had formal education, you would have known that compiled language much faster than interpreted one (same generation)"
Yes your totally right. Ruby programmers are so ignorant. I mean that is why they came up with things like Yarv and JRuby because they had no idea that Ruby was slow and no idea that interpreted is faster than compiled. Stupid ruby programmers!
Pablo June 2, 2009
Java can't be faster than Ruby, and Ruby can't be faster than Java.
Ruby and Java are languages, and they are not by themselves fast or slow. PLEASE TRY TO UNDERSTAND THIS
Implementations of languages (aka Virtual Machines) like MRI, Java HotSpot or JRuby can be faster or slower.
That said, claiming that Java is more scalable that ruby just because one implementation of that language runs code faster than another is plain stupid.
Yeah, your code might be faster, but you are creating applications, not running a fibonnacci number generator, so bottlenecks are (almost always) in other parts of your application, like databases or web servers.
Chris June 2, 2009
Its no surprise to any rubiest that you can create a framework like streamlined that than do all it can in a couple lines of code. But i still dont see the point in it
Brandon Ferguson June 2, 2009
\*looks at calendar\* 2009?
Seriously? Is this conversation happening? The original article was remarkable in how poorly researched it was and to be having language wars over things like generated code is simply hilarious. Reading it and these comments is like being transported back 2-3 years.
Yet Another Java Guy brings shame to his community. And I'm blown away that there's so much seething over rails by java folks.
I've worked .NET, Java, Cold Fusion, ASP, etc. I'm currently a ruby guy. Every language/framework has its issues to think otherwise is delusional. One place I worked underlined it perfectly. We had Spring MVC and other Java sites that took forever to build and were a pain in the ass to change but once up they were up for life (while taking 389 megs of RAM. No more, no less). On the other side they could churn out multiple Rails sites (meaning more revenue) in the same time as one Java one (same programmer on both sides, originally a Java guy). However the caveat was that some would end up being unstable (code quality issue likely) and could take anywhere from 40 meg to 1gig depending the leakiness of libraries used (haven't seen this in a long time). But we could take client requests for changes to their sites and turn them around in a very very short time too.
For these sites things like high end scalability of a framework or language implementation really didn't matter. Getting it to market faster than anyone did. Even 37signals (maker of Rails) doesn't use Ruby for latency sensitive tasks (they actually just moved from some C based pollers to Erlang ones and reduced the amount of processes running from 240 to 3 - even Java would have been far too slow for the task).
In the end it's what's appropriate for the task at hand and for the team you have. There's no superiority to be had here. Ruby and Rails have benefited from many things in the Java world (hell there's even a JVM ruby interpreter), likewise Java has benefited from many things in the Ruby and Rails worlds.
For me - Ruby, and Rails floats my boat and reminded me why I got into this business after having the life sucked out of me using some of the leading languages/frameworks (which still have their uses just not what I was needing it for).
What floats yours?
butch June 2, 2009
Java people referencing Zed comments? come one, all we know that "Yet Another Java Guy" is actually a python troll.
Fadhli June 3, 2009
Wow, reading the comments by java folks and ruby folks and arguing which is faster really reminds me of arguments happen 10 years ago between C/C++ and Java.
Does it got to do with male hormones?
LOL
James June 3, 2009
No one mentioned JRuby? Geez, you take your Rails/Merb/Sinatra/etc. put inside JRuby and fire it up under a Web Application Server (JBOSS, Weblogics, Glassfish) using a WAR file (easy), etc. and it will have full access to all the Java API's and Frameworks. Start out with Ruby then hook into all that Java stuff and manage to meet all those Java only corporate requirements while still maintaining your sanity by using Ruby.
By the way, the two developers of JRuby were hired by Sun a year or two ago!
Start Here: http://wiki.jruby.org/
Fedorov June 3, 2009
Thanks Rails for giving me Grails. Grails floats my boat higher than Rails anytime.
JavaAndRubyGuy June 3, 2009
Holy moly. This article has to be a troll. What browser is that in that first screenshot? IE4? And a developer that uses TextMate? Seriously?
Yeah, that's all superficial... but it can nonetheless provide clues.
Look, Java is fine. If it meets your needs of your organization then use it. Ditto RoR. Now, after having done Java for the previous 7 years I recently started a gig that is doing RoR and have to say that I'm very pleased. BUT I refuse to get religious about it and go the typical "LOL my language/framework rules and your an idiot hurrr" route that seems so typical.
I like RoR. I also like Java. I prefer RoR right now. That may change.
PHP Guy June 4, 2009
When all this has cleared...PHP will still be around. See you guys in a decade or so...
My life for PHP!
Buwahahahaha!
Hugh June 4, 2009
Apple wrote MobileMe in Java and they had huge scaling issues to begin with. Does this also mean Java cannot scale?
Besides Java...
Fadhli June 4, 2009
PHP Guy, I like to use dollar signs on ...
dollars
and not all my functionsss
argh June 4, 2009
@everyone that uses RoR
please call it Rails. RoR is a hideous initialism.
Smart Guy June 5, 2009
Java is the best language.
PHP is also the best language.
Rails really suck big time!
But lets talk about the bottom line --
how much do you earn? As far as I know
I earn far better than Java and PHP devs.
You know which is better if you
are well paid, right?
Rails of Fury! June 8, 2009
First of all, speak English people! Reading this comment thread is giving me a massive headache.
I think Brandon Ferguson said it the best.
"For me - Ruby, and Rails floats my boat and reminded me why I got into this business after having the life sucked out of me using some of the leading languages/frameworks (which still have their uses just not what I was needing it for).
What floats yours?"
Rails floats my boat Brandon, thanks for asking.
So to all the people that are just plain hating because they are ill-informed or have had your boss shoot down your proposal to start using Rails, just stop. It's embarrassing.
Every language/framework has it's drawbacks, performance issues, and quirks that make it unique. I know this war will rage on, but let's not forget that each language/framework has had it's success and failure stories, and the most important thing of all, your code is only as good as you write it. Thanks.
Cole Trickle June 9, 2009
[Comment edited heavily by Jakob]:
From these comments it sounds like a bunch of off shore [Indian Java developers] are afraid they might have to go through another [...] course in another language so they can over bill and under perform in yet another language. Stick to Java and PHP. [...] P.S. Eclipse is a piece of shit.
Jakob S June 9, 2009
Enough's enough. A bunch of Anonymous Cowards spewing insults at each other isn't exactly what I had in mind when I posted about not spreading FUD.
I am sorry I've let it detoriate this far. Comments are now closed. I guess we still haven't evolved from a few years ago, what a shame.
Commenting on this entry has been closed.