The Artima Developer Community
Sponsored Link

All Things Pythonic
Stricter Whitespace Enforcement
by Guido van van Rossum
April 1, 2005
Summary
The Python Style Guide (PEP 8) lists a number of guidelines for the use of whitespace. Since there are still a lot of folks ignoring these rules, here's a proposal for enforcing them.

Advertisement

Python currently gives you a lot of freedom on how to format your code. For example, instead of this:

def fool(one, four):
    year = 2005
    while year < 10000000:
        year *= 10
    return year + four*100 + one

you could just as well have written this:

def  fool ( one ,  four ) :
 year=2005
 while( year< 10000000 ):
                   year*=  10
 return (  year+four * 100+one  )

This is a clear violation of TOOWTDI and enables poorly written code.

Therefore, I propose that as soon as practical, Python should enforce the following rules for horizontal whitespace:

A limited form of vertical whitespace fascism may also be introduced, although this may encounter more resistance, so it may be put off until Python 3.0:

In order to give users sufficient time to adapt their coding style, the new syntax will be optional in Python 2.5, and required in Python 2.6. In Python 2.5, you can enable the strict whitespace checking for a particular module with a future statement:

from __future__ import whitespace

I have hacked up a quick and dirty implementation, which is available at the following SourceForge URL (new, now updated!): http://sourceforge.net/tracker/index.php?func=detail&aid=1175070&group_id=5470&atid=305470

Feedback, as always, is welcome!

Talk Back!

Have an opinion? Readers have already posted 25 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Guido van van Rossum adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Guido van Rossum is the creator of Python, one of the major programming languages on and off the web. The Python community refers to him as the BDFL (Benevolent Dictator For Life), a title straight from a Monty Python skit. He moved from the Netherlands to the USA in 1995, where he met his wife. Until July 2003 they lived in the northern Virginia suburbs of Washington, DC with their son Orlijn, who was born in 2001. They then moved to Silicon Valley where Guido now works for Google (spending 50% of his time on Python!).

This weblog entry is Copyright © 2005 Guido van van Rossum. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use