Confession of a Java Anonymous – Ruby is so brittle, and I like it


Official Ruby logoRuby is so brittle that I would never use it.
– Stéphan

From a Java developer perspective, I thought Ruby was so brittle that I would never use it. How could you survive with a bunch of strings (except on on the beach) ? How could you survive without a compiler ? But in fact this brittleness makes you a better developer, makes better code.

First, the compiler isn’t there so you feel obliged to write tests. You can try without tests but you will not survive a week. Writing tests is the good and only way to go. As you often have less noise in Ruby than in Java, it’s quite easy to get a 70-80% coverage with the nominal case. In Java, you have this false sense of security/confidence : “If it compiles, it works”, so sometimes you omit a test.

Note for the Java developer with the fear of losing the content assist of their IDE: Sublime Text content assist and open files (CTRL-P) are really – really – good.

Second, the duck typing is just great. Do you remember how complex it is to create mocks in Java? Need a double/stub for test, no problem: just instantiate an OpenStruct or Hashie with the appropriate accessors and you are done. No need to “create an interface”, “create a dynamic proxy”, … Remove all this plumbing noise, just code your test.

Third, this fragility and the fact that Ruby has testing built-in, makes writing tests a pleasure, with a framework that rocksRSpec or MiniTest-Spec. The “let”, “describe”, “it”,”should”,”must” wording is just what you need to understand this test code, 6 month after it has been written. Another aspect from these frameworks is the mental shift to model the test. You are no longer tempted to write long test methods with a lot of assert. Instead each feature/behaviour has is own test with one or two assert.

Last, the tooling is just there in SaaS, self-hosted, or in your workspace : minitest-spec or rspec, simple-cov, ci-reporter, jenkins or travis-ci.

Ruby is so brittle, and I like it.
– Stéphan

But don’t take for granted that your is code is 100% clean, just because you picked Ruby. I only wrote about tests, the usual code germs are still there, hiding in the corner: complexity, duplication, undocumented methods, dead code and commented code, bad style

Have you tried PullReview ?

Enhanced by Zemanta

2 thoughts on “Confession of a Java Anonymous – Ruby is so brittle, and I like it

  1. Robert Reiz

    I totally agree with everything in this blog post! I learned Ruby in 2011, coming from Java, and it was the best decision I made in my programmer life. It’s much more fun to write ruby code than writing java code. And the community around Ruby is just awesome. You get very good documentation and if you open a ticket on GitHub you get usually response in 24 hours. I really like it!

    1. Stéphan Mestach Post author

      Thanks. I must admit that it’s also my smartest move in my career. The community behind Ruby and Rails are just awesome. This move to ruby also opened the door to the devops tooling and practices (puppet, chef). I hope this post and your comment will convince a few java-ist to give it a try !


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>