Using tabs effectively. Was: Why not use tabs?

James Logajan JamesL at Lugoj.Com
Thu Jan 20 23:22:37 EST 2000


Joe Smith wrote:
> 
> If one is using all tabs, then putting a comment at the top of the file
> indicating the tab setting seems like a waste.  If one is mixing tabs and
> spaces, then it is needed.  Maybe the comment should be one of the following:
> using all tabs, using all spaces or mixing with a tab setting of X.

Unfortunately, this wont work in general. You may be forgetting that tabs
may also be embedded. For example, consider a file that contains the
following text lines, where ^I indicates a tab:

A^I^Ix
AA^I^Ix
AAA^I^Ix
AAAA^Ix
AAAAA^Ix
AAAAAA^Ix
AAAAAAA^Ix

The intent is to have that look like:

A       x
AA      x
AAA     x
AAAA    x
AAAAA   x
AAAAAA  x
AAAAAAA x

There is only ONE tab setting that will produce that result. You would have
to be either very clever, plow through the possibilities, or be told (via a
comment) for you to discover the original tab setting. (The discovery of the
tab setting used in the example is left as an exercise for the reader.)

Hopefully that explains the reason for my desire to see a comment at the top
of all source files indicating the tab setting, even when spaces aren't
being used.



More information about the Python-list mailing list