Javier has posted 49 posts at DZone. View Full User Profile

A Productivity Race: Ruby on Rails vs JPA on OX3

05.15.2008
| 30003 views |
  • submit to reddit

This article tries to demonstrate that Java can be more productive than Ruby. We are going to develop the same application of the article Rolling with Ruby on Rails Revisited (part 1 and part 2) but using POJOs annotated with JPA and a Model Driven Framework, OpenXava in this case. The result is that with less code, and less time you obtain a more powerful application.

Ruby and rails: The regressive framework

Ruby on rails is so elegant, so easy, so productive. I cannot avoid read and heard continuously these comments. For example, the article Rolling with Ruby on Rails Revisited of Bill Walton says:

What would you think if I told you that you can develop a web application at least ten times faster with Rails than you can with a typical Java framework?”

Oops! Ten times faster!

Well, after these comments I decided to learn Ruby on Rails. I need to know the true key of the productivity and programmer happiness.

After have a taste of RnR I found it a very classic framework, with old techniques:

  • Ruby is a dynamically typed language, as Smalltalk. I prefer statically typed languages.

  • Scaffolding is passive code generation, as IDE wizards or AppFuse. I prefer active code generation, or even better, no code generation at all.

  • Relational database centric: the code generators and ActiveRecord promote think first in tables after in classes. I prefer a more pure OO, as Hibernate, JPA or even ODBMS.

  • MVC: I'm looking for something newer and better that an old MVC framework.

The Java problem: Java developers

The productivity in Java world is a cultural problem, not a technical one. That is this is not a Java fault, it's our fault, we, the Java developers, need to design very beautiful architectures, to apply everywhere the GoF patterns, to do everything reusable, to put 3 tiers in all our systems and to use web services for all. We are not looking for simplicity, therefore we have not found it. But, Java is a very elegant language that allows simpler approach to software development.

Java productivity: The other way

A way for productivity is to use a Model Driven approach. That is, develop the model part, and only the model part, of our application, and to use a framework to produce all the application from it. MDA, OpenXava, Trails, NakedObjects, RomaFramework and JMatter are examples of this approach.

The goal

This is the main screen of the wanted application:

Our goal!

Basically, the app's supposed to do three things:

  • Display a list of all recipes.

  • Create new recipes and edit existing recipes.

  • Assign a recipe to a category (like "dessert" or "soup").

AttachmentSize
rails-vs-ox010.jpg30.22 KB
rails-vs-ox020.jpg81.22 KB
rails-vs-ox030.jpg70.15 KB
rails-vs-ox040.jpg35.47 KB
Published at DZone with permission of its author, Javier Paniza.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Peter Mularien replied on Thu, 2008/05/15 - 3:31pm

While it's great that OpenXava can do something like this (I admit I hadn't even heard of it before), since you are writing this article in 2008, it's not really fair to be following Rails tutorials from 1 or 2 years ago which don't use the Rails 2.x (released in Dec 2007) model of generating scaffolded applications. Although it's interesting that you compared the two approaches, I think that the article would better serve the reader if it were more accurate and up to date on the Rails side.

That said, I do agree with your point that a lot of the problem with Java is with the developers, and the developers responsible for the many heavyweight frameworks that do exist.

Peter Mularien replied on Thu, 2008/05/15 - 3:34pm

Just to follow up to my own comment, there are excellent alternatives to the built-in Rails scaffolding available, such as the ActiveScaffold plugin.

Jonathan Locke replied on Thu, 2008/05/15 - 10:53pm

I am not a big fan of Ruby for anything beyond rapid prototyping. Both dynamic typing and programming by convention have problems when you scale the size of your problem or your team.

There are good approaches to "scaffolding" in Java frameworks which can be just as productive (if not more productive due to API discoverability and strong typing).

A quick taste of this can be seen in this video showing how to create a simple bean editor in Wicket.

One very nice thing Sun could give us to make reflection safer and more convenient for this kind of thing would be some kind of static reflective syntax similar to ".class" for fields methods and properties (yes, I know we don't have properties yet):

  Field f = x.field;

  Method m = getValue.method 

  Property p =  value.property

The need for static reflection comes up all the time and there currently is no good solution.

 

Yardena Why replied on Fri, 2008/05/16 - 3:43am in response to: Jonathan Locke

I agree - SQL code is 17 lines and Java is about 70 (not counting blank lines), and there is very little additional information in the Java code comparing to SQL, most of the code is boiler-plate - every field name is repeated 8 times. If Java had property support, same result could be achieved with about 20 lines of code.

Javier Paniza replied on Fri, 2008/05/16 - 3:56am in response to: Peter Mularien

Hi Peter,

since you are writing this article in 2008, it's not really fair to be following Rails tutorials from 1 or 2 years ago which don't use the Rails 2.x

You are right. Maybe using a article that uses Rails 2.0 would be better. But these article are still cited in ruby on rails site, therefore they are very popular article in RubyOnRails comunity.

Anyways, is it Rails 2.0 MVC? Has Rails 2.0 scalfolding for pasive code generation ?

If the answer is yes, there is not significant difference.

Javier Paniza replied on Fri, 2008/05/16 - 4:32am in response to: Yardena Why

Hi Yardena,

If Java had property support, same result could be achieved with about 20 lines of code.

I agree with you.

This would be more beautiful:


@Entity  
@View(members="title; description; date; instructions")
public class Recipe {

@Id @GeneratedValue @Hidden
property Integer id;

@Required @Column(length=100)
property String title;

@Column(length=255)
property String description;

property Date date;

@Stereotype("HTML_TEXT")
property String instructions;

}

 

Scott Fleckenstein replied on Fri, 2008/05/16 - 9:25am

Nice Troll Job ;)

 Too bad that it doesn't really contain much meat.  While I'm sure there are some segments of development that benefit from scaffolding, being a professional Rails dev I'ved used them exactly 0 times in production.  I realize that scaffolding is very much a part of the marketting effort for rails, but in practice they are quickly thrown away, true to the name scaffolding.  Fancy features are nice and all on the scaffolding, but I would prefer something that I can more easily turn into the end product. You mention that on the Xava side you don't need to write any HTML at all.  do you have the option?  How would I go about taking a template from my front end guy and replacing the scaffold with my *actual* UI?

 The real productivity gains in rails are probably beyond your understanding seeing as you are so new to rails;  doing an article such as this with no experience with Rails paints you as lazy.  The real productivity gainers in rails are spread across several hundred helpers and conventions, until you start to grasp them it's hard to see the point. 

 Better luck with your next article,

Scott

 

 

Javier Paniza replied on Fri, 2008/05/16 - 9:53am in response to: Scott Fleckenstein

Hi Scott,

I realize that scaffolding ... in practice they are quickly thrown away

Then you agree with me that "passive code genartion" is not so good. Really, it's only useful for demos.

OpenXava does not use code generation at all.

You don't need to write any HTML at all. do you have the option?

You can define the layout of the view in an abstract way, using a @View annotation. Look at:

http://openxava.wikispaces.com/view_en

How would I go about taking a template from my front end guy and replacing the scaffold with my *actual* UI?

You cannot. If you have a "fron end guy" then OpenXava is not for you. OpenXava was born for developing business applications, not public internet applications.

OpenXava look & feels adapts automatically to the look & feel of the container portal, currently it support WebSphere Portal, Liferay and Jetspeed 2 look & feels. In this way you have a true feel of integration with you other application of you Enterprise Portal.

An OpenXava application can be in the future be rendered using Flex or JavaFX, and you will not need to change a line of code from your application. Is this possible with rails and its html-like templates ?

 

Scott Fleckenstein replied on Fri, 2008/05/16 - 10:12am

Javier,

Thanks for the response.

 You cannot. If you have a "fron end guy" then OpenXava is not for you. OpenXava was born for developing business applications, not public internet applications.

Thanks for clearing that up.  That's important to know for someone who is comparing and contrasting from the other "side" :)

 

 An OpenXava application can be in the future be rendered using Flex or JavaFX, and you will not need to change a line of code from your application. Is this possible with rails and its html-like templates ?

Yeah, it's very trivial to produce non-html from a model.  Out of the box, active records support JSON, XML, and Yaml.  Here's an example of a single rails action responding to multiple request formats (chosen by either Accept headers or explicit format extensions)

 
def show
@person = Person.find(params[:id]) #load from the db

respond_to do |format|
format.html # => by default would render people/show.html.erb
format.js{ render :json => @person }
format.xml { render :text => @person.to_xml, :content_type => 'text/xml' } #as you can see, there are many options to customize rendering
end
end

Thanks,

Scott

Javier Paniza replied on Fri, 2008/05/16 - 12:16pm in response to: Scott Fleckenstein

Hi Scott,

Here's an example of a single rails action responding to multiple request formats

Yes, but this is the controller part, what about the User Interface? You have to recode/redraw it at hand, have you?

You have not an automatic way for porting a HTML application to FLEX, for example. In a model-driven framework, the UI is automatic generated then you does not need to rewrite it, if you want to change the presentation technology

Fred Barney replied on Fri, 2008/05/16 - 7:31pm

I don't really see the point of comparing this framework to Rails.  The market that will accept entirely auto-generated UIs is tiny (basically limited to enterprises where the ultimate end user's desires are of no consequence, and their productivity of little).  Of course a product specifically geared for that market will be better at it than Rails.  It will also be better at it than a peanut butter sandwich.

Jochen Bedersdorfer replied on Sat, 2008/05/17 - 7:27am

I just wished the discussions would go into the direction of how to support different user-interaction metaphors semi-automatically.

Letting a generator create the UI for you only works for very simple cases.

How could we improve on this? Annotating your model basically with semantic metadata is a step in the right direction (Web 3.0, here we come), but this is not enough to create an acceptable end-user experience for various user interfaces, like web UIs, rich UIs, different devices with radically different look&feel (iphone, windows mobile, android, public kiosks, etc.)

So what we have right now is a number of different render technologies (swing, html-engine, flex, j2me-ui) and layout/interactivity languages (java, html, etc.) and are trying to glue them together to our back-end systems.

None of the above are really very good at describing what an end-user should see and how she should interact with the interface. It is basically still, after all these years, a terrible mess.

I think we need to create a new language or framework that allows you to express in a simple, easy-to-change way what users actually see and how they can interact with it, manipulating data from a back-end using open standards.

There may be a way to express the general behaviour independent on the device the user is using, but you have to be able to optimize it to your users on the different devices down to the smallest detail.

(That is why many java frameworks, who don't allow you to use HTML/javascript/swing-code directly fail miserably)

Is there such a beast out there?

Jonathan Locke replied on Sat, 2008/05/17 - 12:13pm

Well, I recently created a framework on top of Wicket for rendering to mobile devices in multiple markup languages which works pretty well. As always with Wicket, you are working with components (In general, I don't really see how you could solve this problem without a component framework) and directly in the markup language, so you get the fine-grained control you're looking for.  But even with OO Java components, this is quite a complex problem.

A company in the Netherlands called Servoy has a product which runs on both Swing and Wicket which is fairly impressive.

In the end, there is a huge amount of discrepancy between even just the few frameworks listed. A grand unification of user interfaces it's not something coming any time soon. You ask far too much of an industry that took a decade to produce JSF.

 

Javier Paniza replied on Mon, 2008/05/19 - 3:03am

Hi Fred,

The market that will accept entirely auto-generated UIs is tiny

Are you sure?

If the enterprise application development, that until now are written using COBOL, RPG or 4GL, needs front end guys, architects and programmers, then we need 3x of people for develop a Web application that for develop a enterprise application in a traditional way. Even Rails is not so productive as RPG, COBOL or 4GL. OpenXava (or more generally model-driven frameworks) is a solution for this problem.

Enterprise applications is not a tiny market.

Maybe if you need a public internet application a model-driven framework is not the best (although I don't sure at all) and you would need a front end guy.

If you read the article you can see that using OpenXava a simple programmer (as me) without a front end guy can create a nice application.

Javier Paniza replied on Mon, 2008/05/19 - 3:14am

Hi Cochen,

Annotating your model basically with semantic metadata is a step in the right direction (Web 3.0, here we come), but this is not enough to create an acceptable end-user experience for various user interfaces

The trick here is to use a high abstraction level for defining user interfaces. You have to give tips to your model in order to be render, but not the exact way to do it, and the rendered will do the better job for each UI technology.

Look the comment in OpenXava wiki about this issue.

The very first version of OpenXava was a Swing application generator, and in certain moment we worked using both the web UI and the Swing UI from the same source. Unfortunally, in the open source OX version the swing generator is not present, and currently is dicontinued. But, the high level abstraction for creationg application is still there, and future version of OX will support other presentation technologies, maybe FLEX or JavaFX.

Asif Shahzad Ch. replied on Tue, 2012/01/10 - 9:05am

Thank you so much for writing such a nice article. Though I read it very late :( I think, the both approaches to app development will go side by side. OpenXava is entirely different thing from architectural perspective. From architectural or development perspective it should not be compared with ROR, but with Compiere, OpenBravo, Adempiere etc. Yes (at the moment) ROR provides support for better UI, as it separates the UI layer. But from productivity perspective, OpenXava is very promising. Good work OX guys, keep it up.

Agus Hendrayana replied on Wed, 2012/02/15 - 2:57am

Looks interesting, and is LGPL. Might just use that in a future project. *hits "add bookmark"* Good article, thanks!

Agus From Ruby on Rails Developer

Carla Brian replied on Mon, 2012/07/30 - 10:24am

Although I haven't personally read it, Ola Bini's JRuby on Rails book might be a good start. I actually have a copy but just haven't found the time to dig in! -Mercy Ministries

James Walker replied on Sat, 2012/10/06 - 3:05am

The trick here is to use a high abstraction level for defining user interfaces. You have to give tips to your model in order to be render, but not the exact way to do it, and the rendered will do the better job for each UI technology New Braunfels DWI attorney

James Walker replied on Tue, 2012/11/27 - 12:10pm

“What would you think if I told you that you can develop a web application at least ten times faster with Rails than you can with a typical Java framework?” click here

Zem Karlos replied on Sat, 2013/04/27 - 11:34am

Wow....I'm really appreciate your posting it's really informative for me hope you always update more often and share to us what you know. Thanks Orlando roofer

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.