Why not enforce four space indentations in version 3.x?

Ben Finney ben+python at benfinney.id.au
Fri Jul 10 19:35:13 EDT 2009


walterbyrd <walterbyrd at iname.com> writes:

> I believe Guido himself has said that all indentions should be four
> spaces - no tabs.

Yes. That's a “should” and not a “must”, even though PEP 8 says it
with a simple imperative::

    Use 4 spaces per indentation level.

it soon afterward takes a more nuanced tone::

    The most popular way of indenting Python is with spaces only. The
    second-most popular way is with tabs only. Code indented with a
    mixture of tabs and spaces should be converted to using spaces
    exclusively. When invoking the Python command line interpreter with
    the -t option, it issues warnings about code that illegally mixes
    tabs and spaces. When using -tt these warnings become errors. These
    options are highly recommended!

    For new projects, spaces-only are strongly recommended over tabs.
    Most editors have features that make this easy to do.

    <URL:http://www.python.org/dev/peps/pep-0008/>

> Since backward compatibility is being thrown away anyway

That implies a level of abandon that was (AIUI) never the intent.
Rather, backward compatibility was critically examined for whether it
was justified in Python 3.

> why not enforce the four space rule?

Guido has used his time machine to answer your question a few years ago
<URL:http://www.artima.com/weblogs/viewpost.jsp?thread=101968>. (Be sure
to read the discussion in the comments on the article.)

> At least that way, when I get python code from somebody else, I would
> know what I am looking at, without having to do a hex dump, or
> something.

Any text editor that is good for programming (yes, I'm aware this is
perilously close to a “no true Scotsman” fallacy) will have an option
to visibly differentiate whitespace characters, for exactly the reason
you point out.

-- 
 \           “Special cocktails for the ladies with nuts.” —bar, Tokyo |
  `\                                                                   |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list