by Sibers CTO Andrey Gavrilov
In all the talks about web development that have been going on for the last half a year, you may have heard the name of this widely discussed framework, called Ruby on Rails. Even the famous jBoss Seam is often positioned as a competitor for RoR. My curiosity drove me to play a bit with the latter.
First things first – let’s begin with the language. Ruby is positioned as a hybrid between Smalltalk, Perl, etc. Its object model is actually similar to the Smalltalk model, which cannot but please. And what is more, the principles of “minimum efforts” and “least surprise” are sensible enough. What annoys me about it is its Perl-like syntax. Of course, you can write with usual syntax, but some strange code may as well be unreadable.
Let’s get deeper into the language: the “minimum efforts” principle results in some script constructions which are supposed to make the code more convenient. For instance, function arguments can be assigned without parentheses. But what if the arguments include some functions? Right, if slightest ambiguity arises, the language developers advise parenthesizing code. And such examples are numerous.
Or take the principle of “least surprise”. In the Ruby’s object model, inherited from the Smalltalk’s one, everything is an object and all the operations are methods. Hence, 2 + 2 is a specially created synonym for (2) + (2). According to this principle, let’s compare:
1.
for i in [1,2,3]
x = i
end
print x
2.
[1,2,3].each do |i|
x = i
end
print x
Can you guess the difference? In the latter case you’ll get an error message about an unidentified variable as the constructions above are identical except for the variable scope.
Proceed to RoR itself.
Its framework is built up on the MVC pattern:
http://en.wikipedia.org/wiki/Model-view-controller
An advantage here is in generating some default handlers, which can later evolve to the required functional. The generated patterns have the standard functional CRUD, which looks quite impressive:
http://en.wikipedia.org/wiki/CRUD_%28acronym%29
RoR fans claim that writing in it is 10 times faster than writing in ordinary Java frameworks due to the concise language and finely matched default operations. I decided to verify it.
Actually, the framework is fast enough. I think writing in Seam, though, is not much slower as it has an opportunity to build a default CRUD application with the DB structure, but Java is not as good at being concise. The only real disadvantage was the lack of available documentation.
There is the API description and a number of articles and forums. After investigating it a bit, I more or less got it and began developing. The halt occurred when I had to download a file. Having browsing the Internet for about half an hour – because of the mentioned lack of documentation – I realized how to do it. It took 40 lines of code. Pretty heavy, I would say.
The cool thing about it is a sufficient number of plugins, including “Magic Models”, which allows working with dynamically created tables of DB, although in a bit tricky way.
The general impression is rather negative, though. Given modern powerful Java resources – thanks to jBoss – no RoR plugins can equal it. Moreover, among script languages there are such powerful instruments, for instance, as Django (a framework for Python).
P.S. Another “interesting” feature of RoR is a rather low performance. The problem is likely to be the low Ruby efficiency owing to an unfortunate realization of the virtual machine.