Convert Tabs To Spaces

Don't use tabs in code. Make sure your favorite editor inserts a bunch of spaces instead of a tab character when you hit the tab key. Otherwise, indentation nightmares will occur as the code is maintained.

Simply put: unless they're in a makefile, tabs in code are not polite.


I don't know about this. If you use tabs in your code then everyone can have their own indentation settings. Why should I have to look at your code with tab stops every 8 spaces when I like them every 4 spaces? I would think that it would be far more important to set up a generic coding standard within a group that would say to Programmer B "Oh yeah, and we all use tabs so now you do too." or "Oh yeah, none of us uses tabs so please don't."


The amount of indentation is more aesthetic than functional.

Unfortunately, I've had to deal with 1000-line long functions with nested switch statements. When things are this bad, I don't mind how many spaces the indentation is, I just want to know which break statement goes with which case statement.


The important thing is to use either all spaces or all tabs; it's having a mix that screws things up when moving between different tabs lengths.


Unfortunately (fortunately?) my favourite editor (emacs) does it mixed by default, though I have to admit I've never actually figured out how to change this behaviour.

In Emacs: "M-x untabify" will ConvertTabsToSpaces in the region; "M-x tabify" will ConvertSpacesToTabs. The variable 'indent-tabs-mode' controls whether tabs will be inserted when you indent; by default it is true but if you set it to nil then Emacs will insert spaces.


Ideally, each indentation level should be represented by exactly one tab character. That way every user could choose how to expand it. People may end up using 1, 2, 3, 4, or 8 columns per tab. But in practice it's probably safer to use only spaces because we live in a messy world.


ConvertTabsToSpaces is also known as "Do Away With Tabs Altogether" on page ImprovingConvertSpacesToTabs.


See TabsVersusSpaces


EditText of this page (last edited November 27, 2004) or FindPage with title or text search