Tabs should be 8 characters and no correspondance shall be entered into. While that's stupidly wide, at least it's a standard. There is absolutely nothing worse than opening a file and having it look like it was formatted by a two year old chimpanzee on crack.

But vim/emacs support mode lines so you can see which tab width you use!

Except:

They don't agree on the syntax, so you need two sets of modelines, one for each application.

grep/patch/diff/sed/lpr/less don't read modelines.

You can run things through a preprocessor to convert tabs to the correct number of spaces!

A converted diff does not apply as a proper patch anymore. A converted MakeFile bombs out due to a "missing delimiter". A converted sendmail.cf means no mail is delivered.

But they push my code too far to the right

Then your logic is too complicated. Break it into another function to simplify it.

The correct answer is to use 8 character tabs. Sure they are wider than they need to be, but they work. Anyone who tries to tell you that tabs should be whatever else they feel like (2? 4? 5? 6?) needs to be shot. Especially if they ever think that their code is going to be viewed by anyone else, so unless you are writing a proprietary program and never planning on giving the code away or ever showing it to anyone, don't change the tab size.

You can use 4 character tabs and feel fine all along. More importantly, so will the people who open your files.

The key to this state of mind is simple: don't use tabs ANYWHERE but the beginning of the line!!

Well, people can throw a monkey wrench in this scheme if they use overly smrt(sic) editor( setting)s so tabs are used for 8 character gaps and spaces create smaller indentations. Unfortunately, way too many people think this is a good idea and way too many tools support and even suggest this style. This is utterly stupid.

ONLY use tabs to indent. ONLY use tabs at the beginning of a line. ONLY use spaces to line up things in the middle of a block.

Then you can choose your tab width whichever way you like and noone will ever be the wiser from looking at your files.

While this sounds fine, I've never seen it work in practise :( -- PerryLorier

Unbeknownst to many, Nick Gravgaard sets out to solve the problem once and for all

Using spaces to align columns is obviously a kludge, but tabs as they stand now are broken.

The solution - tabstops that expand or shrink to fit their contents

For as long as we continue to define each tabstop as being a multiple of N characters we will never be able to solve this problem satisfactorily. The problem is that we're using tabs and spaces to format text for aesthetic reasons rather than treating them semantically – tabs are for indenting and aligning text, spaces are for separating keywords. The solution then is to redefine how tabs are interpreted by the text editor. Rather than saying that a tab character (a "hard tab") will move the cursor until the cursor's position is a multiple of N characters, we should say that a tab character is a delimiter between table cells in a similar manner to how they're used in tab separated value (TSV) files.

Of course, the question is when (if ever) grep/patch/diff/sed/lpr/less would be taught to follow this approach…

Please note that any user can change the contents of pages on this site,
and therefore the Waikato Linux Users Group can offer no assurances that
the information is correct, and the information on this site is not
necessarily the opinion of the Waikato Linux Users Group, or any of its
members. If you have any complaints about the contents of this page,
please do not hesitate to contact the Waikato Linux Users Group, or, click
the Edit button!

Unless otherwise noted, all pages on this site are licensed under the
WlugWikiLicense.