"Thou shalt indent with spaces"

In Rubygame's "rich and storied life", I've gone through different style phases (and the codebase shows it, if you look closely), usually as a result to exposure to other programming languages or styles.

My preferred indentation style in particular has gone through phases. At various points, I've used width-8 tabs, width-4 tabs, 4 spaces, 2 spaces, width-2 tabs with spaces for alignment, and probably others. Looking back at my old code is like looking back at old yearbook photos — did I really dress like that??

Sometime in the second half of last year, I made a decision that Rubygame code should be indented with tabs, and aligned with spaces, like this:

[tab]def foo( bar, baz,
[tab]         bur, buz )

A logical solution, I thought. It will look right with any tab width! Huzzah! The theory was all good.

Unfortunately, it's a pain in the ass to do in practice. I've yet to encounter a text editor smart enough to auto-indent and align in this fashion. (Not even Emacs, my preferred editor, has a easy way to do this. Or if it does, it's buried among the hundred thousand other options.) So whenever you encounter a situation where you need to indent and align, you pretty much have to do it yourself, typing tab and space characters manually, like an animal!

No, really. I'm lazy when it comes to boring work, and manual indentation and alignment is boring work.

All this is building up to the following point:

My current (and ultimately, arbitrary) preference is 2 spaces per indentation level, spaces for alignment, no tabs anywhere.

This is how I personally like it, at this particular point in time. (And I think this is one of the more popular standards among the ruby and/or rails communities, as it happens.) This is the style I'll be using for Rubygame code for the indefinite future, and I'm considering updating old code to this style as well.

In no way should this post be construed as dictating the "the one true indentation style that everyone in the world must use or they are infidels". I'm not trying to "convert" anyone, so do spare me your pointless holy wars, please.

P.S. The vim commands to express this style are (I think):

sts=2 sw=2 ts=2 et

And you can indent a line with the == command, or indent all lines with %=

For Emacs, you can set (or customize) the following variables:

ruby-indent-tabs-mode nil
indent-tabs-mode nil
standard-indent 2
tab-width 2

And you can indent a line with the tab key, or indent the region with C-M-backslash


shevy submitted a comment on #

personally i am using 2 spaces

the biggest reasons are: i use 80 chars / line (only sometimes a bit more, but other than that i try to follow it)

if i use tabs, i always mis-indent code comments, especially on next lines this is why i completely dropped tabs

Have something interesting to add to the discussion? Email your thoughtful comments to comments@rubygame.org.