A Java Programmer’s transition to Ruby on Rails

There is much out there on the topic of migrating to Ruby on Rails for an experienced Java programmer. I figured I'd add my two cents, as I have finally drunk the Kool-Aid. I switched to Ruby on Rails late last year, and developed a subscription and content management system in Ruby on Rails, went back to a Java project, and then back to Ruby on Rails. The switch back to Java gave me an interesting insight into the things I love and hate about both development platforms.

Ruby vs Rails
At first it was hard to distinguish what Ruby was bringing to the table, and what Rails was. Over time I have learned to love Ruby, as:

  • the code I write is more concise
  • code reads like a sentence
  • code chaining isn't necessarily a bad thing
  • less "useless code" (getters/setters)

For Rails, it was:

  • convention over configuration
  • quickness I could have a web application running
  • generation scripts to facilitate coding
  • testing is easy and part of the framework
  • MVC layout
  • routes rock

At first, I had no idea where to start. I read a Ruby programming book, a Ruby on Rails programming book for Java developers, and a Rails book. By "read," I mean I read most of the Ruby book (skipped the API type stuff) . The two rails books both had layouts where the first half built an application, and the second half went through Rails. I skipped building the application, but skimmed through the steps. The switch from Java wasn't super easy, as I was coming up to speed on both Ruby and Rails at the same time. It was hard for me to write my tests first, because I was struggling with the Ruby syntax. This was exacerbated by the fact that I was writing in a Java style, which doesn't really work in a Ruby world.

IDE

The first thing I did was try to figure out what IDE to use. As a mac user TextMate was apparently the "industry standard," so I gave it a shot. It may have some awesome functionality, but it pissed me off more than it was helping, so I actually used Eclipse (that's what I used for Java) for a while. It actually was OK for Ruby code. I tried NetBeans (the one that supports Java & Ruby) but that just didn't seem to work. I eventually switched to NetBeans for Ruby. After configuring the keyboard shortcuts to use Eclipse commands, I was coding quickly and also was able to run the tests in my IDE. I see many developers who run the server within their IDE (to facilitate debugging), but I generally tend to run it in a terminal window, so I can keep it completely separate from my IDE. I can leave my servers running in the terminal windows and go check out the logs very quickly.

Application Port

I had recently used GWT on a Java project to build an application to manage sports data. I decided to port the application to Ruby on Rails. I tried to keep the existing database schema, but I found that as a newcomer, it was beyond my abilities to get this application up and running quickly enough. I changed the database schema to match rails conventions (and was able to easily change my Hibernate mapping file in my Java app to point to the same database).

As a newbie, I essentially wrote all of my logic in the controller, and had no tests. It was pretty awful, but was a great learning experience. After I produced the application, I had enough Rails knowledge to hop on a project with a more experienced Ruby programmer. We paired on the content management system display logic, and after that I was really up to speed.

Recommendations

If you are an experienced Java programmer, I highly recommend trying Ruby on Rails. It may be better to focus on getting up to speed with Ruby. Create a few applications (not Web apps) that you may see in a code test for an interview. Write your ruby code and tests and get acclimated to Ruby syntax. Once you're there, switch over to Rails. Create a rails project and try something you've done before, or a simple content management system. If you make a CMS, keep it simple: a list of articles, and standard CRUD operations. Create a simple display site, and just demonstrate that you can get some basic functionality out there. Along the way, you'll figure out how to test your code. Now, I write my tests before the code (well - at least on paper), but this was really hard at the beginning, as I was having a hard enough time as it was to get the code working, let alone a series of tests in the same language that was providing said frustration.

I recently created an internal application that helped us facilitate staffing meetings. We had tried a number of methods, but a nifty custom application was really needed. We had a spreadsheet that had some functionality, but really needed to be taken to the next step. I was able to create the basic functionality of the application in about 8 hours, with full test coverage. It has grown since then and we have a huge wish list for it. Looking back, if I had done the initial application in Java, it probably would have taken at least 30-40 hours of just coding (and writing XML). Ruby on Rails isn't the perfect solution for everything, and Java isn't going anywhere, but for many of today's web applications, it's sweet.

Related posts:

  1. Ruby on Rails with Windows – How I made it work
  2. Testing various roles in ruby on rails
  3. From JSP to Ruby on Rails: First thoughts on front-end coding conventions
  4. IntelliJ IDEA and Ruby on Rails
  5. Rails Test Prescriptions is now on sale

Comments: 6 so far

  1. Good article..

    Comment by Subbu, Tuesday, October 28, 2008 @ 11:33 am

  2. Helpful article for those who is starting to learn Ruby on Rails.
    But I am just wondering why a Java developer should prefer learning Ruby on Rails to learning Groovy and Grails framework which are much easier to learn and provide similar benefits?

    Comment by Leonid, Tuesday, October 28, 2008 @ 3:31 pm

  3. @Leonid

    As a Java developer who has made the transition (if that’s the word) to Groovy and Grails, it certainly makes developing in the J2EE environment much more bearable.

    At the same time, they still contain Spring and Hibernate and all those things that tend to make Java webapps somewhat overengineered beasts.

    I’d like to see Spring and Hibernate stripped out of Grails in favor of simpler IoC and persistence solutions that don’t generate 1000 line stack traces in Grails.

    Comment by Dietrich Kappe, Tuesday, October 28, 2008 @ 6:15 pm

  4. [...] here to see the original: A Java Programmer’s transition to Ruby on Rails Share and [...]

    Pingback by A Java Programmer’s transition to Ruby on Rails | 极客社区-新闻博客, Wednesday, October 29, 2008 @ 4:38 am

  5. I am a Java developer that is transitioning to Ruby. I did a project in groovy/grails which made me more curious of Ruby and Rails so I started exploring Ruby.

    I am certain now, after having written both Groovy/Grails and Ruby/Rails projects that Groovy would never offer what Ruby does, and I hope that the JRuby project would dramatically improve in order for Ruby to be used on enterprise projects where a JVM is required. The reason I believe that Groovy could never catch up to Ruby is resources, community and philosophy.

    I learned Ruby from the bottom up by reading “The Ruby Programming Language”, and writing small programs and scripts. I see a lot of potential in the Ruby programming language. Ruby is so much more than Rails and programming in Ruby is such a joy. So my advice for any Java programmer would be to start exploring Ruby as soon as possible.

    Comment by Nadeem Bitar, Sunday, November 2, 2008 @ 5:13 pm

  6. I use netbeans 6.1 with the ruby and rails plugin, and it works fine for both java and ruby programs. I used to be a .net C# developer. I feel that considering that ruby is a dynamic language which java is not, nor is C#.
    They should stop emulating ..remember that dynamic languages are slow. Wonder how well ruby on rails will perform when it comes to reporting and aggregation queries.
    I for one did not use any ORM mapping tools in java or .net because of lack of flexibility with Stored procedures, I started off with using hibernate but thought it would be an overkill..and the configuration file almost killed me.

    Comment by Mahesh, Monday, January 26, 2009 @ 5:54 am

Leave a comment

Powered by WP Hashcash

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com