I realize that the Ruby language is special, in the sense that my learning curve is experienced differently than it was with Java, or even C++ back then. Some steps take a different amount of time, some others are of another nature. Specifically, I find that beyond learning the basics in Ruby (which is arguably quicker than the same in Java), the programmer’s creativity is much more important in Ruby than it is in Java.
Let me take a very simple example. Let’s say you need to write code that needs to trigger something when a post shows up on a specific blog. Here are 2 approaches to this simple programming drift.
The naive approach
You need the job done, you go the imperative way. It’s quick, and it works.[gist https://gist.github.com/cawel/9919a526a2637f54b595]
The Ruby-Way Approach
The naive approach worked, but it does not produce Ruby code, to be a tad nagging. The Ruby-way brings proper abstractions in the picture; a sense of high-level. Props to Mats for the advice on that one.[gist https://gist.github.com/cawel/7e42f7140750e058127a]
Nicer! You see the style? There are a few changes, and most of them are for the better.
Observations and Impacts
everymethod as a top-level construct provides for an interesting abstraction
- monkey patching of
Fixnumadds code readability
Feedclass brings a useful model
FeedNormalizergem removes the feed parsing logic
FeedNormalizergem supports both RSS and Atom
- the high-level functionality at the end reads like English
- more LOC is a minus (although
Feedcould be reused elsewhere)
The Learning Beyond the Basics
With Java, once you learned the basics (for example via a Sun Certified Java Programmer certification), you’re pretty much all set with the language.
With Ruby, after you learned the basics (for example via the PickAxe), you’re not done with the language. You need to become familiar with the idioms and discover all the sugar in the syntax. You need to acquire the Ruby-way.
And of course you will improve your programming skills by being receptive to best practices and patterns, but that’s common to both Ruby and Java.
Acquiring the Ruby-way takes time. It’s not only about using OO principles. It’s also about whether or not you should use monkey patching, choosing the proper abstraction (a top-level method, a module, or a class?), devising elegant closures, as well as what I could call phrasing your code (when is it enough English-like?). It feels like you have important choices to make, which requires responsibility and creativity. Mastering the basics, although necessary, is not enough.
You also need to develop your style. I would dare to say that programming style in Java is enforced by the company code standards, whereas programming style in Ruby comes from the personality and the programming experience.
Ruby programming is art. And it’s part of the reasons why it’s fun.