Why shouldn't I use tabs for indentation? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
开发者_如何学Go Improve this questionIn the Ruby community "everyone" is using spaces (mostly two spaces) for indentation. Since I prefer an indentation level of four spaces I use tabs instead. I think tabs are great because they let the editor show your preferred indentation level. Those who want to read my code with an indentation level of two spaces can easily do that without modifying the file.
But clearly I'm missing something obvious here, since nobody else is using tabs for indentation. For example, these guidelines recommends you to never use tabs, since they "include the practice of mixing tabs with spaces"(?) I can't remember that I have done that a single time in my whole life.
Does anyone else got better arguments for spaces? There has to be, since everyone is using them.
You need both tabs and spaces if you want to do something like this:
def foo:
bar(some, long, argument, list,
continued, on, another, line)
You can use a tab at the beginning of the "bar" line, and another at the beginning of the next line, but then it has to be followed by 4 spaces to make sure the arguments line up (if you used a tab, they would no longer line up with different tab widths). This works perfectly, but mixing tabs and spaces makes people afraid of introducing mixed indentation in the same file, and so often they decide to standardize on spaces alone.
Many editors will let you keep typing tab while inserting four spaces at onces, and handle backspaces as if you had typed a tab, so it works the way you're used to.
精彩评论