Welcome to Dovetail Software Blogs : Sign in | Join | Help

Steven "Doc" List, Agile Novice

VP of Software Development learning to be agile
Idioms

The team had a conversation about Ruby and Rails idioms. I find the whole topic fascinating.

As I understand it, "idiom" means "the way people in this community like to do things". Or even "the clever ways that people in this community have found to do things."

That's not "the best way" or "the most elegant way" or even "the most efficient way".

I went to the Ruby idioms page to see what these idioms were. The starting premise here is that I've been a programmer for almost 30 years, have programmed in a dozen different languages, am comfortable with Object-Oriented Design and Programming, and am relatively new to Ruby and Rails.

Some of the clevernesses on this page made me go "ooooooooooh - cool".  Others made me go "say WHAT?"

My issue is that if it's confusing to read, then I probably wouldn't choose to use it.

Especially if I want other people who are even less familiar with the language, environment, and idioms to understand what I write.

Some of the examples on the Ruby idioms page remind me of the International Obfuscated C Code Contest, which has been around for 30 years or more.

Don't get me wrong - I love Ruby and Rails.  As a programmer, web site designer and developer, and system designer, it makes my heart beat just a little faster with joy.  But that doesn't mean that I embrace all the clever and sometimes incomprehensible things that fall into the realm of idioms.

I look forward to seeing how this all shakes out.
 

Posted: Wednesday, September 12, 2007 10:09 AM by slist

Comments

bret said:

I'm not sure that page is really best resource for Ruby idioms. In general, Ruby idioms represent the communities sense of an elegant, concise way of representing a common expression. They are not intended to be easy to read by people who are not familiar with Ruby. For example, Ruby supplies a "for" command, thus:

for x in [1, 2, 3]

 puts x

end

This syntax is easy for people from many other languages to read. However, the idiomatic way of saying this in Ruby is this:

[1, 2, 3].each {puts x}

This is more concise, and therefore easier for experienced Ruby programmers to read.

Some teams choose to use a style of Ruby that is different the community idiom.

As a lead for the Watir project, i have been moving that project to conform more and more to many of the idioms of the Ruby community because, in the end, i think that makes our code more understandable to more people.

Unlike some other languages, the Ruby community generally frowns on cleverness for cleverness' sake. I would say that Ruby idioms actually do represent the community's views about elegance, although, like i said, I'm not sure i would consider that page the most authoritative reference on the topic.

# September 12, 2007 3:05 PM

slist said:

Excellent points.  No surprise, given the source.

How would I/one find more about the Ruby idioms and Rails idioms?  Is engaging with the community the only way, or are there other pages/sources that would help me learn more?

# September 13, 2007 9:50 AM

Scott Bellware [MVP] said:

Stephen "Doc" List beat me to this post. I was going to write about how some Ruby idioms seem

# September 13, 2007 10:55 PM

bret said:

Just like spoken languages, idioms are used by proficient speakers to express themselves to other proficient speakers. The goal is not really to be understandable to new speakers, but also not usually to cause difficulty either. Many people learning a new language often stumble with the idioms of the language, and complain about why they are used.

The Ruby community often aims for a kind of poetic conciseness. This may take time to appreciate, but it grows on most Ruby programmers. The fact that a sense of elegance that began with Matz has been understood, appreciated and extended by so many says a lot about Ruby, the community, and Matz himself.

The only way to learn Ruby idioms is to engage the community, in one fashion or another. You can do this by reading their code, reading their books, or entering conversation on groups like ruby-talk. This also requires you to understand who is in the community and who is not. There are some people who write Ruby as if it were Java.

There is nothing that says that you have to conform to the idioms of the Ruby community, but it is important for development teams to have their own defined style so that everyone's code looks the same.

The Pickaxe book and the Tailgrind book are two good standards for Ruby/Rails style. I also like the Ruby Way, which has some discussions of Ruby idioms.

Personally, I mostly learned Ruby idioms from reading the code written by solid members of the community.

When we first started on Watir and were new to Ruby, we rejected some of the Ruby norms. We used camelCase instead of box_cars for our method names, and we used one- instead of zero-based indexing. We later came to regret these decisions, and have spent time undoing them. We've converted most of our method names, although the fact that there are two names for many of our methods (which both show up in intellisense IDE's) is a source of confusion. We have also agreed to switch to zero-based indexing, but haven't actually implemented this change, which is sure to cause transition pain.

Other areas were easier to change to current idiom because they were internal to the Watir library and did not affect the API.

# September 14, 2007 10:58 AM

TrackBack said:

# September 14, 2007 4:47 PM

winatbaccarat.co.uk said:

Last night I stayed up late playing poker with Tarot cards. I got a full house and four people died.

# April 23, 2008 5:56 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  

Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS