Monday, February 20, 2006

What I don't have to know

I was thinking recently about how someone with no knowledge of Java or Rails web development would choose which of the two technology stacks to learn. Then I started comparing the lists of technologies on both sides.
  1. For the View you have JSP (Java Server Pages) vs ERb (Embedded Ruby). (We'll assume that (X)HTML, CSS, & Javascript are a given knowledge requirement regardless of framework choice.)
  2. For the Controller you have JSF (Java Server Faces) vs ActionPack
  3. For the Model you have Hibernate vs ActiveRecord. (Since both of these technologies are Object Relational Frameworks we'll assume that relational database knowledge, including SQL is a given requirement regardless of framework.)
So on the surface things look pretty similar. But let's dig a bit deeper.

First let's start at the View: In Rails we take standard HTML and embed Ruby to dynamically generate the content. In JSF-flavoured JSPs on the other hand we substitute HTML tags with custom JSF tags. You must also know JSF EL (Java Server Faces Expression Language) because it is used heavily in the JSF tags.

Secondly, the Controller: In Rails, controllers are written in Ruby. In JSF the controllers are thankfully written in Java but in order to make them work you have to configure the dependency injection framework with XML. Your JSF XML file must conform to a particular DTD. Now if you also believe in the value of dependency injection frameworks you may want to use Spring. Spring isn't mandatory, but it's popular enough to be part of a typical Java stack of technologies. Unfortunately it requires it's own XML DTD.

Finally let's move onto the Model: In Rails we use Ruby to define our model. The naming convention is usually sufficient to allow ActiveRecord to determine what classes map to which tables. We typically use snippets of SQL to tell ActiveRecord how to fetch data from the database. In Java, Hibernate is the common persistence framework choice. In Hibernate another XML DTD tells the framework how to map the classes to the tables. But since people grew tired of maintaining so much XML they turned to XDoclet. And since that became so popular there are now Java 5 annotations that allow you to annotate your domain model wth mapping metadata. Currently you can use any of the three choices. Hibernate also uses its own query language, HQL, to instantiate objects from the database. This query language is based on SQL and has quite a few benefits but is yet another syntactically different language to learn.

So let's add it all up. To do Rails web development you need to learn:
  1. Ruby
  2. the various Rails APIs (e.g., ActiveRecord & ActionPack).
To do Java web development you need to learn:
  1. Java
  2. JSF tag libraries
  3. JSF EL
  4. JSF's XML DTD
  5. Spring's XML DTD
  6. Hibernate's HQL
  7. Hibernate's mapping DTD or XDoclet or Hibernate Java 5 annotations (and the DTD for configuring the framework)
  8. The DTD for web.xml.
  9. The APIs for Spring and Hibernate and JSF
  10. (And I didn't even mention EJBs)
People may look at this list and say "wait a sec, you're being unfair, XML is XML and you're counting four different types of XML in the Java stack". Well all I can say is that when I have to edit one of these things I have to take my eyes off the code that I'm currently working with and make a contextual switch to something that looks very different. That switch is enough for me to penalize the Java list with a bullet point for each one. But even if you collapse the four XML items into one, my point still stands: there seems to be an awful lot more things you have to be comfortable with when developing Java web applications. Perhaps that's why I'm beginning to favor Ruby on Rails so much more. It's the Simplicity.

2 comments:

Anonymous said...

stack of ruby books and java books (http://www.garbett.org/?q=node/25)

Anonymous said...

A comment about: 'XML is XML and you're counting four different types.'

Learning XML is analagous to learning ASCII. It's of little use until you can put it to use, which requires learning something new (like a DTD or schema). The hard part about producing any correct XML file is learning the structure of the file, not learning XML.

For example, the fact that all servlet tags must come before servlet-mapping tags must be known to anyone producing a web.xml file. But that knowledge is completely useless in any other XML file.

I think counting four different DTDs is appropriate in your post. However, I think you'd also have to throw in YAML for Ruby to be completely fair. (of course, once people learn YAML they'll wonder why the hell they continue to use XML).