Reputation: 4732
In reading about rails coding standards, it seems clear that 2 spaces is generally accepted as the way to do things. Why has this gained traction? Is it just the most widely used practice and therefor best to use for consistency, or is there another reason it is actually better than tabs or a different number of spaces?
Upvotes: 31
Views: 19671
Reputation: 2201
It's a matter of convention. The really important thing is consistency.
Most (but not all) developers prefer spaces to tabs because they look the same regardless of any particular text editor / ide setting. http://www.ecyrd.com/JSPWiki/wiki/WhyTabsAreEvil
Two spaces over four is also a matter of convention. Ruby code aims to minimize extra characters, and I suppose extra whitespace goes against this trend.
Upvotes: 35
Reputation: 5859
Upvotes: 24
Reputation: 88378
It comes from Ruby. There is an "unofficial" Ruby style guide here:
http://www.caliban.org/ruby/rubyguide.shtml#indentation
There is no real reason as to why two spaces beats eight or four. Perhaps it is because Ruby code often has shorter lines than Java and C, which tend to use four?
Upvotes: 9