Spaces or Tabs?

In this day and age it seems silly to get into a discussion about whether your companies coding guidelines should have a section mandating either spaces or tabs for indents.  Tabs are clearly more flexible, but I really don’t think it matters at all; people can easily read code that contains spaces or tabs.

But, Microsoft has departed from what seems to be the rest of the world and is mandating spaces in their new Microsoft Source Analysis Tool for C#.

Word is that an update will not only mandate spaces but mandate 4 for indents.

Again, I don’t think it’s much of an issue; except Microsoft Source Analysis Tool for C# doesn’t offer a rule to mandate tabs over spaces.  They’re not providing a tool for organizations to use to enforce local coding guidines, but providing a tool to mandate Microsoft’s coding guidelines.

The tool can be downloaded here and a discussion on tabs can be found here.

kick it on

5 thoughts on “Spaces or Tabs?

  1. I think it matters more when you are doing source control diffs. When users pick different tab/space settings in the IDE it makes a lot of noise for a manual merge.

  2. It’s clearly about time that source code editors ignored whitespace, too.
    Indentation should be enforced by code content, rather than the number of spaces or tabs, so that every time a programmer opens a source file, they see the actual code, indented to their own preferences, rather than the textual representation of it, indented to someone else’s.

    If I write “if (x) { y; z; } else a; b; c;” you should see:
    if (x) {
    } else
    Whether you see this using tabs or spaces is immaterial, indentation should be displayed in the style selected by the programmer, and ignored by version control just as it is ignored by the compiler.
    [Obviously, this isn’t completely possible, as many preprocessor directives and macros will screw up indentation by introducing opening or closing braces]

  3. I think too this rule is kind-a-obsolete, but I don’t think it is meant to forbids the use of the Tab key.
    To me that rule is just recomendation that Visual Studio Tools\Options\Text Editor\C#\Tabs should have “Insert spaces” choosen, nothing else

  4. “Tabs are clearly more flexible” I prefer spaces because then your formatting doesn’t get messed up when reading with a different editor.

    My problem is that I cannot seem to turn the tabs off. No matter what I try my formatting gets messed up when I open the VS2008 .cpp with notepad.

Leave a Reply

Your email address will not be published. Required fields are marked *