Monday, August 01, 2011

Experience report: Ruby

For a long time I've been curious about how the supposed benefits and liabilities of programming in a dynamically typed language1 actually play out in practice. I'm now getting a chance to find it out, since I'm involved in a largish project using Ruby (lots of Rails plus some Sinatra and a couple of random daemons). My professional background has largely been in Java, but I spend a good chunk of my free time learning about different programming languages (and some PL theory), mostly on the static side of the fence. Anyway, here are some notes:

The big question is whether dynamic typing allows for more bugs to pass trough. My answer to this has to be put in context: we are a medium-sized team (between half and a full dozen of devs), all experienced in, and practicing, TDD. As with the rest of this blog post, I don't have hard data to show, but my impression is that the unit tests do indeed catch all the bugs that the Java type system would help to catch; with the caveat that it's often harder to pinpoint the source of a regression. I don't have much real experience in languages whose type systems help to enforce strong guarantees2, but I would imagine they would catch a larger fraction of the bugs that are caught by the unit tests, while not really avoiding further bugs. The reason is twofold: firstly, in my experience, many of the bugs are found in the interaction of separate pieces of software (such as Javascript in the browser talking to the web server), secondly, even when the bug is located within process boundaries, it is most often related to a forgotten invariant than to breaking a established one. But that's all conjecture.

On the matter of productivity, the abstraction mechanisms offered by the Ruby language help to structure code and avoid repetition and that's certainly noticeable in comparison to Java (though, in my opinion, not in comparison to Scala, and probably also not in comparison to Smalltalk, ML, Haskell or Oz). That gain is offset to a point by the lack of refactoring tools. There are some who argue that those tools are made necessary by the verbosity of Java, and aren't needed in better languages. That's nonsense. If a language has an abstraction mechanism, that mechanism is used to define an abstraction and to use the defined abstraction elsewhere. If we then want to change the abstraction we must change code at the use sites as well, and that's where such tools can help. This is all so obvious that I find it almost silly to have to write it down.

Many of the abstraction gains in Ruby come from metaprogramming techniques. I'm not completely sold that they are necessary to achieve the level of abstraction attained, and I'm sure that they hinder readability. It's much easier to gain a footing in a library written with straighforward composition mechanisms (be it functions or classes and objects) than in a mess of Strings and calls to define_method and cousins.

While on the subject of abstraction, I have to comment on Rails. It's a mature web framework that does a masterful job of making the common cases easy. This is a much harder feat than it sounds, as we can glean from the failure of JSF, WebForms and similar unsuccessful attempts to abstract the web. The hidden cost of the bargain is when we get to the uncommon cases. It isn't so much the case that there are specific application features that are hard to code in Rails, though it happens, but that the structure of the code that Rails mandates sometimes isn't a good fit to the problem being solved.

I'm sounding a little negative, so let me balance it out by saying that I believe Ruby and Rails were as adequate choices for our project as any. The main reason is the availability of decent quality libraries and tools (refactoring and code navigation notwithstanding), specially in the often overlooked front of deployment and configuration management.

Apologies for an opinionated blog post.

1. Unittyped, for the pedantic.
2. Such as Agda or Coq, or some styles of programming in ML, Haskell or Scala.


Pedro Matiello said...

+1 to your third paragraph.

madin said...

Tips for buying a copy here. Top Quality Replica Rolex UK People spend a lot of time searching on the Internet,Perfect Replica rolex milgauss watches where there are many replicas of famous designer brands on sale, and we can be sure that they are of high quality and quality.

madin said...

De winkel heeft problemen voor mij opgelost, de service is zeer geduldig, dit is een perfecte winkelervaring. Goedkope UGG schoenen kopen Toen ik de laarzen ontving, vond ik het een goede kopie van de laarzen.kopen dames ugg classic Ik vind deze online winkel leuk, deze laarzen zijn eenvoudig en genereus. Zeer tevreden met deze aankoop.

sandeep saxena said...

I read like this type of article only. You mentioned more important points in this article. Thankyou for interesting article.
C C++ Training in Chennai
C and C++ institute
c c++ course
c c++ training
C C++ Training in Tambaram
C C++ Training in Velachery
JMeter Training in Chennai
javascript training in chennai

priya rajesh said...

Great collection and thanks for sharing this info with us. Waiting for more like this.
Data Science Training Institute in Chennai
Data Science Classes in Chennai
Data Science course in Chennai
R Programming Training in Chennai
Data Analytics Training in Chennai
Machine Learning course in Chennai
Machine Learning Training in Velachery
Data Science course in Anna Nagar

Nathan William said...

One of the most prominent issues the students have to deal with while writing assignments is plagiarism. Hence, they extensively use plagiarism checker to check if there are any copied content in the paper.Choose
Another major reason for using plagiarism checkers is that universities do not accept plagiarized content. Plagiarism is a serious offence. Hence, if found, the students are suspended or might even lose the grades.
Due to these limitations, it is evident that the plagiarism checking & wordcounter tool are not at all effective to check plagiarism. The term plagiarism is actually very broad. It is merely not coping with words. But these tools, unfortunately, detect words but not ideas. Hence, the chances of plagiarized papers remain.

rickypauls said...

Assignment Help is the best source of providing assistance to those who students who could not complete their due to any reasons. If do so, mark your presence on greatassignmenthelp for affordable services.
Assignment Help Online
Online Assignment Help
Assignment Help Online Services
Assignment Helper
Assignment Assistance
Assignment Help Experts
Online Assignment Help Services

darylharper said...

Check the Credit Card Statement by enter login details.

Bill Caster said...

The modes of written communication have evolved over the years and how! What began with emails replacing the old school pen and paper has now moved over to WhatsApp and Hangout messages. How to write a professional Email Barely know how to type in full forms.

Anonymous said...

The pressure of academic assignments can be quite a painful thing. So, if you are feeling wondering, “Who can help me in writing my papers?” then you can simply take the paper help from us at
We boast of a 5000+ strong team of paper writers who are highly qualified and have been providing paper writing help for the past ten years. They can help you submit well-written papers and score better grades. From elementary to high school, from college to university - we provide research paper writing service for all kinds of papers.