[Tutor] tabs or spaces (the endless debate!)

Magnus Lycka magnus@thinkware.se
Mon Feb 17 18:55:02 2003


At 12:00 2003-02-17 -0500, tutor-request@python.org wrote:
> > > Because if you write your code to wrap at 79 chars (which is a good
> > > idea for readability)
> > In my opinion, this is more a legacy problem. On all the major
> > platforms we have editors that can display long lines using scroll
> > bars or methods of scrolling. This isn't vi on vt220 any more :^)
>
>Finally there's the human comprehension thing. When you get very long
>lines it's hard to scan the whole line. While 80 is maybe shorter than
>necessary I'd certainly draw the line at 132 (the other setting on
>my VT220 :-)

I think this is the really important factor.

Why not take the same concerns with code as with other written text.
I'm sure you would all be very irritated if your daily news paper in
tabloid format with a small font used one wide column that went across
the whole page. Your reading speed would crumble. I'm also pretty
sure that you don't like to read text on web pages where you have to
scroll horizontally on each line, because the lines are too wide to
fit on the screen...

All texts on the subject I've seen suggest 60-65 characters per line
on paper. Many suggest that somewhat less is better on screen.

For me, one of the really, really great things with python is that
it's so easy to read and understand python code. Let's not spoil
that!

Too short lines
will slow our
reading down.
This is because
we can really only
concentrate on one
line at a time, and
switching lines too
often will take more
time, than to switch
more seldom. If you
feel that it's faster
to read these short
lines than the ones
above, you can probably
speed up your reading
speed a lot if you
practice. (Unless you
read in a different way
than most other people.)

With code, this is a
problem if we indent
too much, and have a
limited line width. In
most Python code with
4 space indentation,
this is not a problem.

On the other hand, very long lines means that you have to shift focus many 
times on the line, and with a long, rather continous line, it's easy to get 
lost, and above all, it's difficult to find the right next line when the 
line you are reading finally ends. I imagine you've experienced this with 
long lines of text, that you sometimes start to read the same line over 
again, or accidentally skip a line. It very rarely happens with a 60 
character line, but it starts to get irritatingly comman at perhaps 90 
lines or so.

It's not quite the same with code, since those lines that
extend far to the right probably start with a fair indentation.
On the other hand, in code, at least in python code, the location
of the text, both indentation and what line we are in, creates an
essential context for the code. I certainly feel that a need for
horizontal scanning for more than a very small fraction of the
lines of code, would be bad, and I feel that my code is less
convenient to read when the lines get beyond 80 character or so,
so I usually change it if that happens.

Oh well, now I have to crawl back to bed, cure my cold and get well
enough to finish that manuscript review I was supposed to do...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se