Indenting with white spaces, tabs, and how many spaces or the tab width

Viewed 13156

I know that this is more of a coding style, instead of a one right way of doing things. But, I'm a bit frustrated if I came across different indenting formats.

But, I would like to hear the reasons by various people on these issues:

  • Do you use spaces or tabs? Tabs with spaces? Any difference with "Tab insert space", instead of using the space key directly?
  • How many spaces to indent each line of code? Why?
  • Does different code has different style that is more suitable for each of them?

Is there a way to "visually" indent code without actually writing the indent? So it won't ruin the original indenting? It seems unlikely.

I'm using Xcode, so it's better if you have advice for Xcode projects.

8 Answers

An advantage to spaces vs tabs is alignment when wrapping long lines. If you use tabs, no matter what you do, the lines below will most likely not align, unless the editor has the same settings.

For example:

    result = variable_one + variable_two + variable_three +
             variable_four;

If you use tabs, how to ensure that 'variable_four' will show up aligned if tab indentation changes?

Related