java, ruby, python, php, religion, theism, atheism, ignosticism, portfolio, canada, programming, ruby sucks, python sucks, java rocks

Grails and Ruby on Rails OO - Kind of Odd

Posted December 11, 2009

After having worked in Ruby on Rails and Grails for a bit now, something occurred to me that's a little odd about their designs. In this particular observation, both the frameworks end up with the same net effect (but achieve it in different ways). The issue in question is how to declare different methods within your objects, and using HTTP-related objects (such as request and response objects).

The issue is most readily observed in the controller syntax of both frameworks. RoR is a little more OO in this regards in that your controller must extends a basic controller object from the framework. Rails then exposes all the public methods in the controller as "actions" which can be called via a URL. However, there are no parameters passed (this is likely because polymorphism isn't supported in the Ruby language). So how, then, are we to gain access to the HTTP request and response objects? Rails seems to favour using globals for this task. The obvious problem here is that multithreading is ignored entirely - a known and understood shortcoming of Rails, and we can clearly see here how to came to be so.

Grails, on the other hand, does not require extending any base class. As with domain classes, the framework seems to fudge the class at runtime. However, instead of using methods to expose actions, Grails favours the use of named closures. Presumably, therefore, the HTTP request and response objects are passed in as closures variables, which are ultimately invisible in the declaration of the closure. This is marginally better than Rails in that thread-safety is maintained.

My problem with both approaches, however, is the lack of formal parameter declaration. Love it or hate it, knowing what parameters are passed, and what exceptions  can be thrown often helps a programmer. It's almost as if both development teams were so fanatical about reducing the amount of typing a programmer has to do that they ignored debugging. This can be particularly seen in Grails, where any underlying domain class problem requires modifying the Log4J settings to display all hibernate messages (I know that this is being addressed somewhat is Grails 1.2, but the point is still valid).

I do understand the point of coding speed, really I do, but what I'm finding is that the learning curve is actually quite brutal for both frameworks because of the amount of things are not immediately visible. To me, having to Google everything seems more tedious than typing maybe a dozen or so letters out.

Most of this is really just personal preference, so ultimately it's all moot, but this is my opinion.

Comments

I ran across your blog today when researching some stuff for groovy and ruby. I've written RoR for a little over a year now, but at work we've started using Groovy/Grails. I'm starting to like Groovy/Grails a little more every day, but still desire writing Rails code every now and then.

Anyway, this sort of all falls under the convention over configuration thing and was actually one of the biggest gripes of Java Servlets (since you always had to specify the HttpServletRequest/Response in your get/post methods). If every closure or method always requires those, why do I always have to specify them? Especially in a framework where it is clearly documented that those items will always be passed in?

Grails clearly states what is passed into the closures and it's not as if it's something that you may gloss over. If you're learning Grails, it's the first thing you tend to learn... as it's also the first thing you learn when doing Servlets that you'll need HttpServletRequest/Response as params.

Somewhat similar is how C++ hides the "this" pointer to all of the class methods. When you write C++, it's a given that you'll have to have a pointer to "this" in every method, but the C++ compiler does not require you to have to write it out, it just slaps it in there for you during compile.

Also, I must state that what's the purpose of wanting a controller of a web framework to be thread safe? I can't think of a time when this would be necessary and if it's never necessary, then what's the point in worrying about it or possibly reducing speed or even readability in making sure it's thread safe? Web requests are always executed one at a time and there is no reason to make a controllers action run in parellel with itself. The web server does all of that work for you.

Add comment

Visit my Friends and Family

If you've enjoyed my site, please take a moment to visit my friends and family, many of whom have some interesting insights, and entertaining thoughts and ideas.

Widgets

Advertising


Windows 7 Sins
 

ss_blog_claim=07d81221ccea23e9eae5fdaf510cea20