Introduction: Ruby on Rails is just one aspect of making Ruby very powerful, just as EJB is part of the Java Enterprise platform. Andrew Glover reveals what Java developers can do with Ruby.
Before I begin this article, I need to clarify a few things. First, it's not an article about Ruby on Rails. If you want to learn about Rails, there are articles and blogs that are relevant every week (or even hourly), and they all add up to the many features of this exciting framework; see resources for a list. Second, this article is not intended to predict that Java's better language, tools, and frameworks will go down in the face of Ruby on Rails. So this article does not cover topics that are most commonly associated with Ruby recently.
Don't get me wrong--I think Rails is unbelievable! It is extremely powerful and has dramatically changed the face and pace of Web development. I just want to point out that Ruby is a lot more functional than Rails, especially from a Java developer's perspective.
The specialty of Rails is Web site development, but I haven't built a brand new Web site myself. Most of the Web sites I work with have been built with Struts, Tapestry, or other technologies. When I was using Ruby, I basically used it as a development practice for interfacing with the Java platform. So in this article, I'll talk about how to exploit Ruby if you're primarily a Java developer.
The feeling is so different
Ruby's syntax differs from that of the Java language. First, Ruby has no brackets or semicolons, and it makes the type completely optional. One might say that Ruby's syntax is concise, and that's what it's all about: The language allows developers to quickly write concise code.
If you define the same class separately in the Java language and Ruby, you can see this simplicity by comparing. Let me first give you two classes of--word and Definition (like a dictionary) written in the Java language. In the simple class diagram shown in Figure 1, you can see that the two classes have several relationships (if this complexity seems unnatural, please bear with it; it makes sense!) ):
A word can have a collection of synonyms (instances of Word).
A Word also has a Definition collection.
A Definition has an aggregation association to Word.
Figure 1. A simple dictionary with words and definitions