« +1 | Main | Pragmatic Unit testing in c#: good book, hard to read »

Tabs versus Spaces in a nutshell

Tabs versus Spaces: the tab is a presentation macro, not a character - the fact that some bearded idiot made it an ascii character is an unfortunate decision we're stuck with. If you're too young to know what ascii is, tab is a bit like the bold or font tag in HTML - also unfortunate decisions. Tab characters don't belong it source code, ever - only idiots put tabs in source code. Map the tab key to multiple whitespaces instead - I don't care how you do it, just get it done. No, I don't care what you do with bold tags in HTML. No. No. No.


April 23, 2004 10:07 PM


(April 23, 2004 10:23 PM #)

I completely disagree with your assumption that tabs never belong in files. I used to agree with you til, I started at a job where some of the developers were coding with 8 space tabs. There is nothing worse than an 8 space tab, but I couldn't get them to change it. The solution is to use tabs, and then anybody and set the tab size to whatever they want 2,4, 8, heck even 3. Haven't had a single problem with it in over 4 years.

Carlos Villela
(April 23, 2004 11:30 PM #)

Matt, you're spot on, here. But if "tabs are presentation macros", as Bill and jwz suggest, then why can't that macro mean "indent"? If it's just a presentation macro meaning "this is an indented piece of code", why not use it?

Bill de hra
(April 23, 2004 11:31 PM #)

Matt, Carlos,

My tongue is firmly in cheek - I need to work on that sense of humour!

(April 24, 2004 12:13 AM #)

I do the same thing all the time. And as far as I can tell jwz isn't really open to other people's opinions or changing his own!

Asbjrn Ulsberg
(April 24, 2004 12:48 AM #)

Actually, I agree with you, Bill (even if you're ironic). Tabs make the source code ugly. Many says that when using tab characters, it's just to change the number of spaces the tab should be for each programmer, but that's not the case. Vertically aligned columns gets screwed like a rabbit in hunt season when this is done, so it's not more dynamic than using a regular space character.

To get neatly aligned code, no matter what the programmer's preference are, spaces is the only way. To get fckd code no matter what the programmer's preference are (unless it's the same as yours), use tabs. Yah! Tabs for president!

Asbjrn Ulsberg
(April 24, 2004 12:50 AM #)

I use two spaces in all of my code, btw. That's more than enough. 8 spaced tabs is a certain proof of a deceased mind.

(April 24, 2004 02:49 AM #)

Whitespace is for sissies. Think of all the disk space you're wasting with your spaces and newlines (and don't even get me started on those Windows losers with their double-character EOLs!).

(April 24, 2004 12:11 PM #)

I use one-space tabs !

(April 25, 2004 12:23 PM #)

I'm a tab many for one reason: navigation. I find it much easier to navigate around a document using the arrow keys when tabs are involved rather then having to pound the keys as I do with spaces.

David Boxenhorn
(April 25, 2004 12:34 PM #)

Multiple spaces are just as much presentation as tabs. If you were using a semantic markup for programming (not worth the effort in my IMHO, but let's say you were) you would want a <NEST></NEST> element (maybe one exists...)

Damian Cugley
(April 29, 2004 06:40 PM #)

If I remember correctly, USCD pascal had a special 2-character escape sequence that abbreviated N blank spaces, so that any amount of indentation would have the same cost...

You could improve on the navigation issue by having editors that jump over *any* horizontal whitespace sequence with one press of the arrow key. Even better than when using tabs!

Pat Niemeyer
(April 30, 2004 07:16 PM #)

You can go from tabs to spaces trivially, but not the other way around - ergo tabs contain information about the structure of the code that is not contained in spaces... and you are the idiot ;)

Pat Niemeyer
Author of Learning Java, O'Reilly & Associates

(April 30, 2004 07:27 PM #)

If navigation is an issue - use a decent text editor.

This discussion should always be solved in the workplace with the following instruction:
"The next person that brings up this ridiculous argument gets fired."

Bill de hra
(April 30, 2004 07:42 PM #)

"ergo tabs contain information about the structure of the code that is not contained in spaces... and you are the idiot ;)"

Nah - how about this:

"You can go from tabs to spaces trivially (and still read and compile the code), but not the other way around - ergo tabs contain noise irelevant to the structure of the code, noise that is not contained in spaces... tabs are for idiots ;)"

Works for me :)

Marcus Sundman
(May 1, 2004 11:53 AM #)

Jamie Zawinski is an idiot that apparently hasn't really even thought about how to indent with TABs. Just look at this quote: "I just care that [...] it's possible to look at a file and know what interpretation of the TAB character was used, because otherwise it's just impossible to read." When TABs are used for block-indenting it doesn't matter how your editor interprets them. The source code will still be correctly indented and very readable (although it might be indented more or less than the viewer prefers, but this is easily corrected by visiting the editor settings).
The problem people have with TABs is that there are a few morons that use them wrong, and idiots like Jamie Zawinski who think TABs must be used wrong if used at all. TABs should be used to indent blocks of code (i.e. one indention level equals one TAB, and if a line should be indented more than the block it's in (e.g. if it's a continuation line, such as a function argument list where you want to do visual alignment) then the additional indention whould be done with spaces). For this they are much better than spaces. However, you MUST NOT use TABs to align argument/variable/function lists, nor should you ever do something as moronic as mixing TABs and spaces when indenting (like in emacs).
See e.g. this page: http://www.derkarl.org/why_to_tabs.html

Trackback Pings

TrackBack URL for this entry: