Attention developers: You must set your text editor to tabs-at-8. There's nothing to discuss, no other viable option, and anything else would be crazy. If you're writing in Python, that is. I only recently discovered this fact, and it adds a new wrinkle to the mostly decomposed dead horse known as The Tab Wars.
For those who aren't familiar with Python, it has the distinction of being one of very few computer languages in which white space is significant. Specifically, the indentation of the code determines the block structure; there are no braces or other clutter to tell the interpreter otherwise. It takes a little getting used to, but is actually quite nice. "Then what about tab characters?" I wondered one day.
For the indentation to be unambiguous, the language must know how to interpret a tab character relative to spaces, and Guido chose tabs-at-8, presumably because that was and remains the most common defacto standard (more on that later).
So let's say you are working on some python code that looks like this:
You're thinking, Cool, I get a bonus! But, as it turns out, you have your tabstop setting at 4, not 8, and moreover the code has been edited by a variety of people with a mix of tabs and spaces and what you really have before you is this mess:
Now we know that python uses tabs-at-8, by definition, so what it will actually see and do is:
and you will only get your bonus when pigs fly. And that's just not right.
How did we come to this? What can we do about it? Sit right down and you'll hear a tale.
Eons ago, early hominids produced text on mechanical devices known affectionately as "type writers". Many of these devices included a cool feature whereby little "tabs" of metal could be put at various places along the "carriage" (the thing holding the "paper") and a special key (the "tab key") would cause the carriage to advance to the next such tab. This was very handy for lining things up vertically (itself an ancient artform, largely forgotten, but I digress).
About one eon ago, things got all modern and teleprinters (literally: print from afar) appeared, followed a few short decades later by the American Standard Code for Information Interchange—the ASCII we know and love to this day. Among it's 128 codes are 33 control codes, most of which are far too powerful and unstable to be used anymore, but Code 9 is our friend The Tab. More properly, the Horizontal Tab (HT), because there is also a Vertical Tab (VT) but let's just pretend there isn't. The tab codes were intended, and in fact used, to cause printing to jump to various places that had been manually configured into the teleprinter for a particular print run—so things would line up nicely on pre-printed forms and whatnot. But people soon realized that this was insane and they stopped doing it.
Now while they could have just used ASCII 32's (space characters) to position things, apparently it seemed too much of a shame to abandon an entire control code, so instead they decided, not entirely formally, that henceforth Code 9 would mean "advance to the next multiple of 8 characters on the current line"—what we today call "tabs-at-8". This also provided a nice 8:1 compression of whitespace, something that mattered to people when each bit cost several dollars to store or send.
"Why 8?" you ask. Interestingly enough, the value 8 was chosen by Satan, because he could see the future and likes to cause trouble.[citation needed] So tabs-at-8 was then widely adopted and for years and years countless computer programs (and programmers) simply assumed that that was what ASCII Code 9 had always meant and would always mean.
Then things got even more modern and someone realized that it wasn't terribly difficult for a given text program to let a User (we've heard about them) select how many characters a tabstop should be! Whoohoo, by simply changing an editor setting you could instantly... mess up all your indentation? Make your text file randomly incompatible with various other programs? I really don't know what the point was but someone thought it was really cool, and the idea spread like hoola hoops in the late 50's.
Despite the Tabs Liberation movement, tabs-at-8 remained a standard of sorts, including things like HTML, CSS, most Unix utilities, and of course the Python programming language, to name a few. So of course the idea of user-selectable-tabstops faded away, everyone settled into living with the devil's tabs-at-8, ASCII files were universally unambiguous, and there's nothing more to say, the end. Well, not quite.
As it happen, we can still find one small exception to the de facto standard interpretation of ASCII code 9 as a horizontal tab aligned on 8-character boundaries. In the mid 1970's a young college dropout started a company called Microsoft. This company has since risen to some prominence in the field of software development, and the designers of its flagship development environment—Visual Studio—were struck by the overwhelming beauty of tabstops matching indentation. Additionally they could see the sheer godliness of indentation at 4 chars. Ergo: Visual Studio comes preconfigured with tabs and indentation set to 4 for all languages. All but XML, that is, which is set to 2 and 2 for reasons I don't want to try to imagine. And of course for Python it... oh, there's no Python configuration for the VS editor. Never mind.
Of course it's very easy to just say "Microsoft is evil". It's also fun, try it! But MS evil or no, countless hoards of developers work in Visual Studio daily, using the editor defaults, because, after all, where are these settings anyway? And they enjoy the sheer godly beauty and perfection of tabs at 4, indentation 4 and all is Good and Just in their sight. If only Everyone could share in this beauty and join with them in peace and harmony oh what a wonderful ASCII world it would be.
Sadly, for some reason there remain hundreds—perhaps thousands—of developers who simply refuse to do all their work in Visual Studio. I can't explain why this is, but they are stubborn. More often than not these troublemakers will not have tabstop set to 4 in their editors. They might even have their editor set to insert spaces instead of ASCII 9 codes. In fact, it turns out in the end that the only way to defeat Satan's tabs-at-8 trickery is precisely to set your editor to never allow those Code 9's into your file in the first place! Replace tabs with spaces. ASCII code 32 is, after all, the only unambiguous sort of space you can put in an ASCII file.
Still, if you are fortunate enough to live in a 100% Pure Microsoft Development World—and you never code in Python—then you are free to retain the myriad and compelling benefits of tabs 4, indent 4, keep tabs. It's a lovely thing and I'm sure you will be very happy, and you'll barely hear Satan laughing if you plug your ears and go la-la-la-la-la. Everyone else will have to suffer with Insert spaces, with whatever indentation is suitable for the language they happen to be using. And they'll survive. Just please be nice and don't touch their code.
One final thing. It pains me but I am compelled to mention the one glaring exception to the No ASCII Code 9's rule: Makefiles. The Makefile grammar specifically requires that ASCII Code 9 be used to introduce command lines; spaces simply will not do. As wikipedia gently states: "This aspect of the syntax of makefiles is often subject to criticism." Count me in on that.
Maybe later we can explore end-of-line characters.