simpleweb/ruby-style-guide

Name: ruby-style-guide

Owner: Simpleweb

Description: A community-driven Ruby coding style guide

Created: 2012-11-14 09:51:56.0

Updated: 2013-01-13 03:40:34.0

Pushed: 2012-10-18 07:00:45.0

Homepage:

Size: 151

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Prelude

Style is what separates the good from the great.
– Bozhidar Batsov

One thing has always bothered me as Ruby developer - Python developers have a great programming style reference (PEP-8) and we never got an official guide, documenting Ruby coding style and best practices. And I do believe that style matters. I also believe that such fine fellows, like us Ruby developers, should be quite capable to produce this coveted document.

This guide started its life as our internal company Ruby coding guidelines (written by yours truly). At some point I decided that the work I was doing might be interesting to members of the Ruby community in general and that the world had little need for another internal company guideline. But the world could certainly benefit from a community-driven and community-sanctioned set of practices, idioms and style prescriptions for Ruby programming.

Since the inception of the guide I've received a lot of feedback from members of the exceptional Ruby community around the world. Thanks for all the suggestions and the support! Together we can make a resource beneficial to each and every Ruby developer out there.

By the way, if you're into Rails you might want to check out the complementary Ruby on Rails 3 Style Guide.

The Ruby Style Guide

This Ruby style guide recommends best practices so that real-world Ruby programmers can write code that can be maintained by other real-world Ruby programmers. A style guide that reflects real-world usage gets used, and a style guide that holds to an ideal that has been rejected by the people it is supposed to help risks not getting used at all – no matter how good it is.

The guide is separated into several sections of related rules. I've tried to add the rationale behind the rules (if it's omitted I've assumed that is pretty obvious).

I didn't come up with all the rules out of nowhere - they are mostly based on my extensive career as a professional software engineer, feedback and suggestions from members of the Ruby community and various highly regarded Ruby programming resources, such as “Programming Ruby 1.9” and “The Ruby Programming Language”.

The guide is still a work in progress - some rules are lacking examples, some rules don't have examples that illustrate them clearly enough. In due time these issues will be addressed - just keep them in mind for now.

You can generate a PDF or an HTML copy of this guide using Transmuter.

Table of Contents
Source Code Layout

Nearly everybody is convinced that every style but their own is ugly and unreadable. Leave out the “but their own” and they're probably right…
– Jerry Coffin (on indentation)

Syntax
Naming

The only real difficulties in programming are cache invalidation and naming things.
– Phil Karlton

Comments

Good code is its own best documentation. As you're about to add a comment, ask yourself, “How can I improve the code so that this comment isn't needed?” Improve the code and then document it to make it even clearer.
– Steve McConnell

Good code is like a good joke - it needs no explanation.
– Russ Olsen

Annotations
Classes
Exceptions
Collections
Strings
Regular Expressions
Percent Literals
Metaprogramming
Misc

Contributing

Nothing written in this guide is set in stone. It's my desire to work together with everyone interested in Ruby coding style, so that we could ultimately create a resource that will be beneficial to the entire Ruby community.

Feel free to open tickets or send pull requests with improvements. Thanks in advance for your help!

Spread the Word

A community-driven style guide is of little use to a community that doesn't know about its existence. Tweet about the guide, share it with your friends and colleagues. Every comment, suggestion or opinion we get makes the guide just a little bit better. And we want to have the best possible guide, don't we?


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.