March 14, 2006
Re: The appeal of Ruby over Java
Earlier today I read with interest a list of reasons why Ruby on Rails appeals to Todd Huss more than Java. Like Todd, I've been experimenting with Rails but Java continues to pay my bills and I still enjoy developing J2EE apps. For a while I've been mulling over what I see as the strengths of Rails compared to J2EE. Now let's see if I can enumerate a few from my experience.
First of all, some background. Over the last few months I've been developing a Rails app that I've called, for want of a more inspired name, Cricket Coach Helper. I've enjoyed it because it has given me a chance to get my hands dirty with Rails (beyond following the example in the book) and in the process build an application that has proved quite useful to me. For those of you familiar with cricket, the app has allowed me to record details of players, competitions, fixtures, match scores and to generate statistics (e.g. batting, bowling, fielding and partnerships) for the team that I have been coaching.
So what impressions of Rails has this experience left me with?
- The quick start to development was a delight!
Installing Rails was a breeze. Then in a short time I had run
rails crichelpto generate the structure of my application, created my development database with aPlayerstable, configured mydatabase.ymlfile, runruby script/generate scaffold Player Admin::Playerto generate CRUD code for the Players table and pointed my browser tohttp://localhost:3000/crichelp. I was ready to test my first iteration! - Incremental development and learning was usually quick and easy.
As I progressed beyond some straightforward CRUD functions I soon encountered use cases where a scaffold didn't cut the mustard. But, like Todd, I found that I could learn more details of the Rails framework as I needed them. Having the PDF versions of both the Rails book and PickAxe handy has been invaluable. Using WEBrick as a development web server also smoothed the way. And having the structure of the application pre-defined by Rails allowed me to concentrate on incrementing the application's functions rather than refactoring infrastructure code.
- I like the simplicity of Active Record.
I think the way Active Record integrates the tables with the Ruby model classes is simple, clean and elegant. The way it infers attribute names from column names is liberating when compared to Java equivalents (I know Hibernate and TopLink have more flexibility to overcome impedence mismatches but how often is that really a problem?). And having the relationship declarations (e.g.
has_many) together with additional methods that may be required all in the same Ruby class makes so much sense (It's an unfair comparison but I've just had an awful flashback to generating CMP Entity Beans!). - It has been a delight to improve my working knowledge of Ruby.
As I get to know Ruby better one reason I like it so much is because it reminds me of Smalltalk. Blocks and closures are sadly missing from Java. And I think duck typing works well too. However, I'm well aware of the debates about the relative merits of strong and weak typing. Anyway, I like Ruby. For example, it allows the programmer to manipulate collections so much more elegantly and tersely than Java (even Java 5).
- For relatively simple apps I'm happy with the Rails MVC approach.
The convention over configuration approach is definitely a strength of Rails. The structure to support separation of MVC concerns is a given. So there's no mucking about at the start of a project making decisions about standards to ensure MVC concerns are separated using a consistent approach. That's all good as long as Rails supports the technical requirements, which is not always going to be the case (e.g. responding to asynchronous messages is a case that is well supported in J2EE by JMS and message-driven beans).
- Using rake for testing the model worked well.
The use of rake for automated unit testing of the model was similar in many ways to my experience of JUnit. However, I was particularly impressed with the way fixtures have been built into Rails. This is another good practical example of the productivity to be gained from the convention over configuration philosophy. On the downside, and I know this is trivial, I did miss seeing the JUnit green bar!
- Despite the power of TextMate I found myself wanting an IDE.
TextMate is an excellent code editor for Rails development, especially because it recognises Ruby and Rails syntax. I definitely found it superior to using Eclipse with the Ruby plugin, mainly because TextMate shows Embedded Ruby syntax in the view files whereas the Eclipse Ruby plugin is dumb as far as rhtml files are concerned. However, I could not help but yearn for the helpful features of an IDE like Eclipse. Simply being able to use code complete in Eclipse to find methods quickly or in conjunction with code templates is such a productivity booster. Anyone who argues that languages like Ruby, Python or Groovy are more productive because you have to type less is being blind to the huge benefits of a sophisticated IDE.
- I'm still not convinced about the ability of Rails to scale.
I need to research this topic more but to date I haven't seen a rigorous analysis of the ability of Rails to scale compared with J2EE. This is any easy target for those defending J2EE against Rails and I don't think reporting that a Rails site handled 2.5 million requests in a day is helpful or rigorous.
- There does not appear to be good Apache support for Rails.
This is another topic that I need to research more. However, from what I have read, Apache's support for running Rails via FastCGI is problematic. I know that lighttpd is an alternative for production deployment but if it is problematic to run Rails on the world's most popular web server that would appear to be a limiting factor to widespread adoption. As I said, I need to learn more about Rails deployment so if you think I'm talking rubbish here, I'm happy for you to politely correct me.
- Rails and J2EE both have strengths and weaknesses.
I think Rails has a good fit for relatively simple web applications that typically provide a web UI to a database. I've seen web applications developed using J2EE for which that technology was an unnecessarily complex choice. Rails offers a promising alternative now. However, J2EE is not going to go away any time soon. It is a mature technology, is undergoing significant improvements (e.g. EJB 3.0) and is trusted by many corporations who have made a significant investment in it (wait on, that sounds like a defence for COBOL!). And, for some applications, it will be a more appropriate choice than Rails.
There you have it. Ten impressions from my experience with Rails so far. It will be interesting to see how much of an impression Rails makes on the market over the next year or two.
Posted to Java, Rails, Software Development by Keith PittyHi Keith, I'm happy to hear that you like the development experience of Ruby on Rails. We're all about optimizing programmer happiness, so it's great to see it paying off.
What specific questions do you have around scalability? Rails employs a Shared Nothing, which means adding twice the app hardware gives twice the throughput.
So any scaling issues that will occur in Rails does so at the database level. Some times that can be migrated with caching, other times with dataset partitioning, and other times again just with some big iron back there. Largely the same way any other web-application stack that uses a relational database does it.
Re: Apache/FCGI. This is actually the preferred configuration of the majority of big Rails sites (ODEO, 43things, Basecamp, Backpack, etc). Most people are doing so with Apache 1.3/FCGI (which is a very stable combo, once you overcome the slight annoyance of setting it up). And the Apache people are all over FCGI development for Apache 2.2.x with mod_fcgid and friends.
But I agree, Java is not going anywhere in neither the short or medium term. Any technology that at some point or another played any significant role in the industry is still around in some form or another.
Posted by: David Heinemeier Hansson at March 15, 2006 11:13 AMNice work Keith, and I couldn't agree more with your conclusion.
One minor nit-pick though, I think that the distinction is not between "strong and weak typing" but rather between static and dynamic typing. Javascript has weak dynamic typing, Ruby (and Python for that matter) have strong dynamic typing, Java has strong static typing.
Aahz explains that topic much better than I can here;
http://www.artima.com/weblogs/viewpost.jsp?thread=7590
Posted by: Andy Todd at March 15, 2006 1:54 PMDavid: Thanks for your comments, especially with respect to scaling.
At this stage I don't have any specific questions about scaling (maybe later) and I appreciate the broad thrust of your answer. What I think would be useful would be an article explaining in some detail how Rails achieves scalability. If it is as simple as you say perhaps it won't be a lengthy article. Nevertheless, something for people to point to, perhaps a case study on how the deployment of Rails has allowed 43things to scale, would be useful.
Re Apache/FCGI, I guess it's time for me to get my hands dirty ;)
Andy: Mea culpa! Thanks for the correction.
Posted by: Keith Pitty at March 15, 2006 2:04 PMWith regard to scaling, now that I've fully read chapter 22 (Deployment and Scaling) of the book, I have a better understanding. And it does contain three brief case studies, including 43things. I'd still like to see more case studies, with a little more depth and perhaps more skewed to business applications.
Posted by: Keith Pitty at March 16, 2006 10:29 AMFor Ruby On Rails development, I recommend Netbeans 6.0. It is by far the most advanced Ruby IDE
Posted by: pcdinh at August 9, 2007 11:57 PM
