2 Spaces or 1 Tab, what's the standard for indentation in the Rails Community?
I've noticed that most of the HTML/XML/HAML that gets generated from plugins uses 2 spaces instead of 1 tab. I use textmate and have tabs set to 4 spaces for HAML/HTML/XML and 2 spaces for Javascript/Ruby, but I only have to press the tab key once to get nice indentation. Pres开发者_Python百科sing the space bar twice and delete twice seems like too much work :p.
Do you manually type two spaces, or is some middle layer converting tabs to two spaces? Or do just a few of you use tabs?
2 spaces is generally agreed-upon.
As for all the arguments about different editors showing tabs with different widths...
It is a configuration setting people!
Change your editors to use two spaces for each tab. Different widths in different editors is not an argument. It is a moot point. If anything, using tabs allows people who prefer different widths to set and use the width they prefer. Hell, I think I like 3 spaces.
And you have to hit backspace twice just to un-indent something once. I'm a programmer, I'm lazy. I don't like to do things more than once!
2 spaces. Even for the plain Ruby kids.
Two spaces are emerging as the standard because they are “just enough” indentation to make the HTML clearly indented to most people's eyes, but because HTML tends to nest very deeply — much more deeply than one would commonly nest when programming — and anything more than two spaces tends to start pushing HTML off the right edge of an 80-column screen pretty quickly.
Do not use tabs; use two spaces. Tabs are problematic because they can be a different width in different editors (and terminals, for that matter). Since whitespace is removed when you tidy your HTML before deployment, there is no ultimate bandwidth benefit to using tabs; they simply introduce a wildcard into your development experience.
I use Emacs, which auto-indents XML, HTML, and SGML with two spaces. I would be quite annoyed if I had to type indentation characters by myself; that's why I have an editor. :)
2 spaces is the convention for Ruby which Ruby on Rails is based upon.
In more practical terms, if you use mutliple OS and editors ( such as at work I used RubyMine on Win XP and TextMate on my MacBook at home and one of our developers uses Notepad ++ and another Aptana and we even have one who uses Netbeans, all of these editors interpret tabs differently - different indentation, but 2 spaces are always 2 spaces. Also if you ever use HAML or if you need to copy paste your code into some websites that try to colorcode your code, 2 spaces are essential.
精彩评论