Non-Indented python

Terry Reedy tjreedy at home.com
Sat Nov 24 13:59:45 EST 2001


"Huaiyu Zhu" <hzhu at mars.localdomain> wrote in message
news:slrn9vv07k.1f7.hzhu at mars.localdomain...
> There are really two issues involved:

I see at least three questions with respect to indents and cursor
placement:
1. What should one type -- space or tab?
2. What should be displayed (if you type a tab)?
3. What should be transmitted and stored (in electronic versions)?

There are at least two purposes for tabs:
1. place cursur (or typewriter platen) where you want to put next
character;
2. save transmission time and electronic storage space by compressing
spaces.
The second purpose is essentially obsolete, making the first the
correct one.

This gets to the question: What is or should be the meaning of <tab>.
Lets consider some of the possible contexts: prose, tables, code
(omitting poetry ...).

For prose using paragraph indents, the first tab stop should be that
indent.  For typescripts and printer versions thereof, the American
standard is/was 1/2 inch or 5 spaces.  Printed books often use fewer.
A logical tab can be variably interpreted more easily than multiple
spaces.

For tables, the ideal (based on my considerable experience preparing
published tables) is one tab per column, using tab variants that right
justify columns of integers and align columns of decimal numbers.  The
physical interpretation of such logical structure markers should be
defined by a separate tabstop definition, which can be adjusted as
needed.

For code, the visual indent should be enough to differentiate levels
but not so much as to jam (short) lines up against the right margin of
the display surface.

> If everything can be redesigned from scratch, what would be the best
> indentation method for languages like Python's?

When I do code Python, which is currently not often, I use double
spaces as being barely adequate, quick to type, and preferable to tabs
that become 8 spaces.  When I start using an adjustable-tab code
editor, I'll switch to 3 or 4 spaces.

> There is a strong argument for one tab character per indent level.
> When indentation is encoded as the number of tab charactors,
> code can be exchanged between different  programmers
> completely unaffected by the display style.

Though this is not what I currently do, and even though I currently
use a stupid news reader (Outlook Express) that deletes tabs, I find
myself agreeing.  This is the same argument I made above with respect
to prose and tables: tabs should be regarded at logical structure
markers rather that as fixed-meaning format characters.  It is also
one of the driving forces behind the development of XML and related
standards: the realization that logical structure is distinct from
physical format and that premature formating cramps possible uses of
electronic files.

> In this situation, what's the best distance between tab stops?

No such thing as a general absulute.

> If tabs were used to help reducing key strokes while typing a table
on a typewriter, 8
> makes most sense, because 8x8=64.

Nonsense.  5x16 = 80.  Trying to ascribe a fixed-format meaning to
tabs contradicts the argument made above for treating them as logical
markers.

In any case, defining <tab> as "move to the next multiple-of-8
position (+ 1 if using 1-based indexing)" is possibly never right from
a functional viewpoint.  It is wrong for prose, where just about the
only tab needed is for paragraph indents.  It is wrong for tables,
except by accident, since it leads to the hell of mixed spaces and
tabs (speaking from experience, again).  It is wrong (too large) for
coding.  Maybe some poets would find it useful.  It is sadly ironic
that the 'standard' interpretation is almost never right.

<rest of stuff I pretty much agree with snipped>

Terry J. Reedy







More information about the Python-list mailing list