The Elements of Ruby Style

The Elements of Style is a fantastic little book detailing best practices for writing.

It's written as a series of rules about the best way of writing clear, concise elegant writing.

Subsequently, there's a series of programming language books that do a similar thing. One on my bookshelf is Baldwin, Gray and Misfeldts The Elements of C# Style that provides style guidelines for C#.

For example:

Element 73: Choose Simplicity over Elegance

...there is nothing particularly elegant about a 50 line sequence of if-else statements, but if it's the simplest most straightforward approach to the problem, there is no reason to turn it into something it does not need to be.

And other tasty tid-bits.

If there's ever a language that's just CRYING out for a definitive style guide, it's Ruby. Rubyists are such purists about style, simplicity, DRY etc - but there doesn't seem to be (at least not to my eye) a list from on high as to best practices for style issues.

That was until I found Ian Macdonalds Unoffical Ruby Usage Guide that seems to be a pretty exhaustive study into Ruby best practices.
For example:

We recommend two blank lines between each class and module definition, and a single blank line between each method definition


oo - I also see Jeremy McAnally has created a project to do just this. Find it at: Elements of Ruby Style

Subscribe via RSS

Back to all blog posts