Tabs vs Spaces
Moderators: phlip, Moderators General, Prelates
-
- Posts: 213
- Joined: Wed Sep 10, 2008 3:54 am UTC
Re: Tabs vs Spaces
Four seems like a decent tab size. Two is a bit small, eight is definitely too big, and 3 isnt a power of two.
However, I have yet to find someone unhappy with tabbing to the correct level of indentation, then using spaces to set alignment (I actually hate alignment. I also hate "spaces between operators and variables" though. I'm a rebel)
However, I have yet to find someone unhappy with tabbing to the correct level of indentation, then using spaces to set alignment (I actually hate alignment. I also hate "spaces between operators and variables" though. I'm a rebel)
Re: Tabs vs Spaces
I always have pointers as "ClassName * instanceName" because I love spacing things out.
but I stand by my original post, tabs are the only choice for indentation.
but I stand by my original post, tabs are the only choice for indentation.
Re: Tabs vs Spaces
Tabs for indentation, spaces for alignment.
- lurkersanonymous
- Posts: 12
- Joined: Thu May 01, 2008 12:09 am UTC
Re: Tabs vs Spaces
Surprised no-one has linked this yet.....

I have ViM set to convert entries from the <Tab> key into 4 spaces for Python and Java. For WRAMP Assembly it is 8 spaces, but that is because the compiler gets upset if that is not the case.

I have ViM set to convert entries from the <Tab> key into 4 spaces for Python and Java. For WRAMP Assembly it is 8 spaces, but that is because the compiler gets upset if that is not the case.
This just in from the tether ball Court, Obama's friend said Ms. Clinton has cooties.
Re: Tabs vs Spaces
I have started following the Google C++ style for C and C++ and their ObjC styles for ObjC.
http://google-styleguide.googlecode.com ... pguide.xml
and
http://google-styleguide.googlecode.com ... cguide.xml
Which is honestly pretty close to how I was doing things before, now I just stick to things like roughly 80 characters a line, and I shortened my naming schema a bit.
http://google-styleguide.googlecode.com ... pguide.xml
and
http://google-styleguide.googlecode.com ... cguide.xml
Which is honestly pretty close to how I was doing things before, now I just stick to things like roughly 80 characters a line, and I shortened my naming schema a bit.
# drinks WAY to much espresso
Re: Tabs vs Spaces
I believe Factor forbids tabs in source files, so there is no competition there.
Re: Tabs vs Spaces
lurkersanonymous wrote:Surprised no-one has linked this yet.....
There is a case to be made for mixing tabs and spaces, though: use tabs for expressing the indentation level and spaces for lining things up. Or rather, set up your editor to format the whitespace in this way.
Code: Select all
int f(int x,
......int y) {
--->return g(x,
--->.........y);
}
That way, everyone can view the code with the amount of indentation they prefer simply by changing the tab size.
Re: Tabs vs Spaces
Phaedrus wrote:That way, everyone can view the code with the amount of indentation they prefer simply by changing the tab size.
except for those who prefer to eschew indentation in favor of alignment, like so:
Code: Select all
int f(int x, int y)
{ x = g(x);
y = g(y);
return h(x, y); }
Code: Select all
factorial = product . enumFromTo 1
isPrime n = factorial (n - 1) `mod` n == n - 1
Re: Tabs vs Spaces
Code: Select all
int f(int x, int y)
{>x = g(x);
->y = g(y);
->return h(x, y); }
Last edited by Phaedrus on Thu Jul 23, 2009 12:06 pm UTC, edited 1 time in total.
Re: Tabs vs Spaces
hotaru wrote:except for those who prefer to eschew indentation in favor of alignment, like so:Code: Select all
int f(int x, int y)
{ x = g(x);
y = g(y);
return h(x, y); }
I really gotta say, that does not, in my opinion, improve the readability of the code at all, simply because the brackets are seemingly thrown into a syntax that doesn't make sense. I can understand the logic behind it, but it really does not improve the situation in C or C like languages at all.
# drinks WAY to much espresso
-
- Posts: 38
- Joined: Fri Jun 05, 2009 10:20 am UTC
- Location: About 4.91E11 feet from the sun.
- Contact:
Re: Tabs vs Spaces
MHD wrote:1 press on the tab key = 4 spaces.
PERIOD!
End of discussion. 2 spaces is too small, 3 spaces is weird, 5 is too much, 8 is way too much, and hard tabs suck, especially because you'd thing they were 8 actual spaces in one editor, load it up in another, and they'd be 6 or 4 visible spaces wide, and some of the lines wouldn't match.
Re: Tabs vs Spaces
Two spaces, maybe because I'm use to Lisp...
- phlip
- Restorer of Worlds
- Posts: 7562
- Joined: Sat Sep 23, 2006 3:56 am UTC
- Location: Australia
- Contact:
Re: Tabs vs Spaces
null1024 wrote:Hard tabs suck, especially because you'd thing they were 8 actual spaces in one editor, load it up in another, and they'd be 6 or 4 visible spaces wide
Why is this a bad thing? If someone who prefers to indent by 6 characters loads your file, they'll see it in their preferred 6 characters. And when they edit it (using hard tabs too, as presumably this would be a company style guide or something) and you load it, all their new code is shown indented by 4 characters, how you like it.
null1024 wrote:and some of the lines wouldn't match.
Only if you do it wrong.
Code: Select all
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵╰(ಠ_ಠ ⚠) {exit((int)⚠);}
Re: Tabs vs Spaces
Tabs can accommodate everyone!
Code: Select all
// Tab size: 8 // Tab size: 4 // Tab size: 2
int f(int x, int f(int x, int f(int x,
......int y) { ......int y) { ......int y) {
------->return g(x, --->return g(x, ->return g(x,
------->.........y); --->.........y); ->.........y);
} } }
int f(int x, int y) int f(int x, int y) int f(int x, int y)
{------>x = g(x); {-->x = g(x); {>x = g(x);
------->y = g(y); --->y = g(y); ->y = g(y);
------->return h(x, y); } --->return h(x, y); } ->return h(x, y); }
Re: Tabs vs Spaces
Tabs for indentation, spaces for alignment sounds great in theory, but people inevitably screw it up and make a mess of the source. It doesn't help that most editors get this totally wrong.
Re: Tabs vs Spaces
Let the editor take care of the tabs and spaces for you. Vim has the Smart Tabs plugin, Emacs has Smart Tabs code for several languages, IntelliJ IDEA has a "Smart Tabs" option, and GNU Indent can be persuaded with -i99 -ts99 -l999. Works as part of the auto-indentation.
Re: Tabs vs Spaces
I use tabs for others convenience, but have set my tab width to 1. Suddenly it doesn't matter which one I use, provided no-one else uses my code.
Meaux_Pas wrote:I don't even know who the fuck this guy is
- kernelpanic
- Posts: 891
- Joined: Tue Oct 28, 2008 1:26 am UTC
- Location: 1.6180339x10^18 attoparsecs from Earth
Re: Tabs vs Spaces
Tabs. But the awesome, auto-multiple of 4 tabbing that emacs has.
I'm not disorganized. My room has a high entropy.

Bhelliom wrote:Don't forget that the cat probably knows EXACTLY what it is doing is is most likely just screwing with you. You know, for CAT SCIENCE!

Re: Tabs vs Spaces
Spaces. Any decent editor has an Expand Tabs option which exists for all those who are aware just how much Tabs fuck everything up.
- phlip
- Restorer of Worlds
- Posts: 7562
- Joined: Sat Sep 23, 2006 3:56 am UTC
- Location: Australia
- Contact:
Re: Tabs vs Spaces
Such as?OOPMan wrote:how much Tabs fuck everything up.
What exactly to tabs fuck up, that isn't an example of the person doing the tabbing Doin It Rong (by which I mean failing at using tabs for indenting and spaces for alignment)?
Code: Select all
enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵╰(ಠ_ಠ ⚠) {exit((int)⚠);}
- Amnesiasoft
- Posts: 2573
- Joined: Tue May 15, 2007 4:28 am UTC
- Location: Colorado
- Contact:
Re: Tabs vs Spaces
Gotta go with phlip here, the only way tabs-for-indent/spaces-for-alignment can mess things up is if you're doing it wrong.
Re: Tabs vs Spaces
Tab = Arbitrary symbol that can be translate into X spaces where X is a random number between 1 and infinity
Space = An arbitrary symbol that indicates exactly 1, you guessed it, space!
Now look that happens when I open that file written by MacGuyver over there with mixed Tabs and Spaces. Alignment failure. If I wanted to sort through MacGuyvers poorly indented text and I would been an Journalism/Creative Writing tutor and he'd be yet another uselss BA undergrad.
Either uses spaces or uses tabs. If you're going to use tabs, use expandtabs. If you're not, get the hell of my lawn. This is not a democracy. You do not get to choose how many spaces your damn tab equals. Tabs are for socialists and other people who think that other people should be allowed to make ANY choices at all about ANYTHING. In my country, you use a space to indicate a space and that's it!
Space = An arbitrary symbol that indicates exactly 1, you guessed it, space!
Now look that happens when I open that file written by MacGuyver over there with mixed Tabs and Spaces. Alignment failure. If I wanted to sort through MacGuyvers poorly indented text and I would been an Journalism/Creative Writing tutor and he'd be yet another uselss BA undergrad.
Either uses spaces or uses tabs. If you're going to use tabs, use expandtabs. If you're not, get the hell of my lawn. This is not a democracy. You do not get to choose how many spaces your damn tab equals. Tabs are for socialists and other people who think that other people should be allowed to make ANY choices at all about ANYTHING. In my country, you use a space to indicate a space and that's it!
Last edited by OOPMan on Wed Jul 29, 2009 3:13 pm UTC, edited 1 time in total.
- Amnesiasoft
- Posts: 2573
- Joined: Tue May 15, 2007 4:28 am UTC
- Location: Colorado
- Contact:
Re: Tabs vs Spaces
You seem to misunderstand what we mean by usings tabs for indenting and spaces for alignment.
Now what happens when I change my tab size to 2?
How about 8?
When you only use tabs to indent and only use spaces for alignment, it will work regardless of your tab size. Unless maybe you have word wrapping on...but if you have word wrap on, you're clearly doin' it wrong.
Code: Select all
int foo(int ..bar,
........float baz) {
--->ArbitraryFunctionName(3.141,
--->......................0, 0, 0);
--->return 0;
}
Now what happens when I change my tab size to 2?
Code: Select all
int foo(int ..bar,
........float baz) {
->ArbitraryFunctionName(3.141,
->......................0, 0, 0);
->return 0;
}
How about 8?
Code: Select all
int foo(int ..bar,
........float baz) {
------->ArbitraryFunctionName(3.141,
------->......................0, 0, 0);
------->return 0;
}
When you only use tabs to indent and only use spaces for alignment, it will work regardless of your tab size. Unless maybe you have word wrapping on...but if you have word wrap on, you're clearly doin' it wrong.
Re: Tabs vs Spaces
This isn't about tabs and spaces!
This is about choice!
Tabs = Choose your own Spacing!
Spaces = Use the Spacing I give you!
Any sane individual will go with the latter option because the former involves relying on other people, entities which can generally be shown to most likely to do the WRONG thing.

This is about choice!
Tabs = Choose your own Spacing!
Spaces = Use the Spacing I give you!
Any sane individual will go with the latter option because the former involves relying on other people, entities which can generally be shown to most likely to do the WRONG thing.

Re: Tabs vs Spaces
OOPMan wrote:Any sane individual will go with the latter option because the former involves relying on other people, entities which can generally be shown to most likely to do the WRONG thing.
People make mistakes whether tabs or spaces are used; that's why auto-indentation was invented. (How could you else trust people to indent nested code consistently?)
The problem with spaces is there's no general agreement on how many to use, so the value used by the auto-indentation must be changed from project to project. Tedious. With tabs, the setting is always to emit one tab per indentation level, whether a tab is displayed as two columns or four.
Tabs are used consistently, but displayed differently; spaces are displayed consistently, but used differently.
And again: tabs for indentation, spaces for alignment. It is the auto-indentation's job to distinguish between the two, so you don't have to, just like you don't reformat huge sections of code by hammering the space bar.
Re: Tabs vs Spaces
Tabs have the following clear advantages:
1 keypress to adjust indentation, not 4
75% less file space (for a test sample consisting of 100% tabs equivalent to 4 spaces each)
If you use spaces, you hate America. Not just the US, you hate all of America. Even Canada and Mexico and Brazil.
Tabs use ONE character to represent ONE logical entity: An indentation.
Spaces use 4 characters and require the use of adjustment macros just to change the indent size.
It's like using a package manager... automating the problem instead of fixing it.
1 keypress to adjust indentation, not 4
75% less file space (for a test sample consisting of 100% tabs equivalent to 4 spaces each)
If you use spaces, you hate America. Not just the US, you hate all of America. Even Canada and Mexico and Brazil.
Tabs use ONE character to represent ONE logical entity: An indentation.
Spaces use 4 characters and require the use of adjustment macros just to change the indent size.
It's like using a package manager... automating the problem instead of fixing it.
-
- Posts: 4
- Joined: Wed Feb 03, 2010 10:32 pm UTC
Re: Tabs vs Spaces
Always spaces. Set VIM to expand tab to spaces.
Also map the tab key to word completion (if you're typing a word) Add the following to your .vimrc:
Taken from here: http://vim.wikia.com/wiki/Autocomplete_ ... ping_words
Also map the tab key to word completion (if you're typing a word) Add the following to your .vimrc:
Code: Select all
function! Tab_Or_Complete()
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
Taken from here: http://vim.wikia.com/wiki/Autocomplete_ ... ping_words
Re: Tabs vs Spaces
Spaces, since I don't want my code to be indented 8 space because I loaded it into notepad, or at places where I can't change the tab indentation.
Re: Tabs vs Spaces
achan1058 wrote:Spaces, since I don't want my code to be indented 8 space because I loaded it into notepad, or at places where I can't change the tab indentation.
http://portableapps.com/apps/developmen ... p_portable
Tis nobler in the mind to take arms against a sea of failure, and, by opposing, end it.
Re: Tabs vs Spaces
Except that you might be using a Thin Client that does not have workable USB, not does it allow you to run random programs. (Though I personally try to stay away from doing anything more than e-mail with those things.)
- Meteorswarm
- Posts: 979
- Joined: Sun Dec 27, 2009 12:28 am UTC
- Location: Ithaca, NY
Re: Tabs vs Spaces
achan1058 wrote:Except that you might be using a Thin Client that does not have workable USB, not does it allow you to run random programs. (Though I personally try to stay away from doing anything more than e-mail with those things.)
Have internet, will vi.
The same as the old Meteorswarm, now with fewer posts!
- flying sheep
- Posts: 63
- Joined: Sun Jan 31, 2010 12:35 am UTC
Both
tabs for indentation, spaces for alignment, (like emacs’ smrt tabs linked to above) so would be one of those who get beaten up:

but imho indentation is mostly bad coding style:
for huge constructors use variables (like kaboutdata. in my example, they indented, but this is not necessary since the arguments are used in the order the variables are assigned)
and if you want to create big string lists use text files or databases, don’t mix data with code!

but imho indentation is mostly bad coding style:
for huge constructors use variables (like kaboutdata. in my example, they indented, but this is not necessary since the arguments are used in the order the variables are assigned)
and if you want to create big string lists use text files or databases, don’t mix data with code!
Re: Tabs vs Spaces
Here are the basic rules I follow at work :
Indenting C/C++/Java : 4 spaces
Indenting HTML/XML etc : 2 spaces (otherwise it's too verbose)
I've also worked on a 1M+ line, 20+ year old software package that is a combination of both C and C++. In it there are mixes of all coding styles, brace styles and indenting styles from an uncountable hoard of programmers using vi/vim/emacs/<inset editor or ide here>.
I've got to say the only way to ensure a measurable amount of readability is to banish all tab characters. At least with spaces it's always consistent. The number of files I found with mixed space/tab indenting was huge, and my general fix was to reindent entire source files using spaces only. Problem solved.
Indenting C/C++/Java : 4 spaces
Indenting HTML/XML etc : 2 spaces (otherwise it's too verbose)
I've also worked on a 1M+ line, 20+ year old software package that is a combination of both C and C++. In it there are mixes of all coding styles, brace styles and indenting styles from an uncountable hoard of programmers using vi/vim/emacs/<inset editor or ide here>.
I've got to say the only way to ensure a measurable amount of readability is to banish all tab characters. At least with spaces it's always consistent. The number of files I found with mixed space/tab indenting was huge, and my general fix was to reindent entire source files using spaces only. Problem solved.
- flying sheep
- Posts: 63
- Joined: Sun Jan 31, 2010 12:35 am UTC
Re: Tabs vs Spaces
swich tab and space and your last paragraph would read:
python is a little bit more difficult (in both directions), but possible, too. your choice is a matter of personal taste.
and still be wrong, since you can retab everything just like you can respace everything.I've got to say the only way to ensure a measurable amount of readability is to banish all space characters. At least with tabs it's always consistent. The number of files I found with mixed tab/space indenting was huge, and my general fix was to reindent entire source files using tabs only. Problem solved.
python is a little bit more difficult (in both directions), but possible, too. your choice is a matter of personal taste.
- flying sheep
- Posts: 63
- Joined: Sun Jan 31, 2010 12:35 am UTC
Re: Tabs vs Spaces
but still tabs are better 

lulzfish wrote:Tabs use ONE character to represent ONE logical entity: A [single level of] indentation.
Spaces use [a variable number of] characters and require the use of adjustment macros just to change the indent size.
It's like using a package manager... automating the problem instead of fixing it.
Re: Tabs vs Spaces
Tabs. Have your editor decide how wide they should be. The only problem are people who refuse to spend the time configuring their editor.
Re: Tabs vs Spaces
I'm coming in on the side of tabs. The current code base I work on is standardized to use four spaces, and our editors are set to expand tabs to spaces. I hate when I hit the tab key one too many times and I have to hit the backspace key four times to undo it.
Re: Tabs vs Spaces
People who use spaces for indenting should be thrown into a burlap sack, beaten with sticks, hung in the office parking lot, and set on fire for all to see.
Spaces for indenting make keyboard navigation annoying.
Spaces for indenting make keyboard navigation annoying.
Summum ius, summa iniuria.
Re: Tabs vs Spaces
Pesto wrote:I hate when I hit the tab key one too many times and I have to hit the backspace key four times to undo it.
Hm, tried shift+tab?
I like to think of indentation as indentation, whether it's tabs or spaces. Use indent and dedent operations in your editor. Then you don't even have to think about tabs vs. spaces. Many editors use tab and shift+tab (typically, you'll need to select some text on the line(s) to make the tab key indent rather than insert a tab). For vim it is >> and << for the current line (and . to repeat) or V, then j/k to select some lines, then just > and < (again, . to repeat). Using = (or == for a single line) will indent correctly according to brackets. All good editors will do this for you. Except ofc in Python

phlip wrote:Ha HA! Recycled emacs jokes.
Re: Tabs vs Spaces
Tabs.
Why does everyone claim 8 is too much? Assuming the average length of a line is 40 characters (an overestimate, IME), and you want to avoid going over 80 characters (although for some lines, it might happen), that gives you 40 characters of indentation. 5 tabs. If you're nesting any deeper than that, you're screwed anyway. Whereas people who use 4 spaces think it's ok to do 10 levels of indentation, and people who use 2 (which appears to be the emacs default for some languages) think it's ok to do 20 levels...
Why does everyone claim 8 is too much? Assuming the average length of a line is 40 characters (an overestimate, IME), and you want to avoid going over 80 characters (although for some lines, it might happen), that gives you 40 characters of indentation. 5 tabs. If you're nesting any deeper than that, you're screwed anyway. Whereas people who use 4 spaces think it's ok to do 10 levels of indentation, and people who use 2 (which appears to be the emacs default for some languages) think it's ok to do 20 levels...
Who is online
Users browsing this forum: No registered users and 3 guests