The ONE TRUE WAY to use tabs (Re: Tabs versus Spaces in Source Code)

Andy Sy andy at neotitans.com
Sat May 20 08:31:23 EDT 2006


achates wrote:

> Yeah - we've got to the repeating ourselves stage.

Actually a couple of the responses on this newsgroup
have settled the question for me.  I did learn something
new by engaging in this holy war.


Tabs need not be evil, but ONLY if they are used in one
particular way:

If you really must use tabs, use them *ONLY* for 'semantic'
indentation and use pure spaces when you need arbitrary
indentation (e.g. arbitrary spacing).

PHP Example
===========

function xyz() {
->print  "This is a really really really long line that I'd ".
->       "like to extend to the one down below while preserving ".
->       "ease of readability by aligning the start of the string".
->       "lines.  I use tabs to reflect syntactical (e.g. semantic) ".
->       "indentation, but use spaces for arbitrary indentation.\n\n".;
->while (10) {
->->print "This code will align properly no matter what tabsize setting ".
->->      "the reader uses, and is the only real benefit of using tab ".
->->      "characters instead of pure spaces.\n\n";
}



I did some basic tests, and it looks like this style should also
work for Python code.


THIS IS THE *SINGLE* CORRECT WAY TO USE TABS IN CODE!  ANYTHING
ELSE WILL BE A PAIN FOR PEOPLE WITH TABSIZE SETTINGS DIFFERENT
FROM YOURS!!


> But that's the problem with this issue: it's really hard to get the
> space-indenters to actually think about it and to address what is being
> said. Every time it comes up, there's always a few people trying to
> explain why tabs give are a good idea, facing a whole raft of others
> spouting stuff like:

Most of the tab-indenters have the same attitude.  But I did get ALL
of my points against tabs addressed this time.  And thank you to those
people including you for the 'less -x<tabstop>' tip.



> But unfortunately the situation is worse than that: tab indentation
> needs to be actively defended.

A world where everyone uses pure spaces would be far far far better
than the current situation where tab users can't even decide what
the universal tabsize should be and whose code alignment breaks
on different tabsize settings.

However, a world where EVERYONE who uses tabs strictly practice the
ONE TRUE TAB WAY would be a *slightly* better place than one where
everyone used pure spaces.

And remember, the ONE TRUE TAB WAY does not come for free and involves
a certain amount of tedium and attention.  It will be impractical on
most simple text editors.  For most people, I frankly don't think the
minor benefits are worth it.



> Unlikely perhaps. I hope so. It's a cruel irony that Python's creator
> didn't appreciate the benefits that tab indentation would bring to his
> own language - the only major language in which indentation levels
> actually have semantic significance.

You might want to run those benefit/s/ by me again, because the SINGLE
benefit I can still see to using tabs is so that people who have
different indentation width preferences can view code according to
the way they want.  And remember, this benefit will ONLY occur
IF people stick to using the ONE TRUE TAB WAY outlined above.

Any other method of tabbing would just be worse than a pure-spaces
world.




--
It's called DOM+XHR and it's *NOT* a detergent!




More information about the Python-list mailing list