← All Posts · ← Previous · Next →

Stricter Whitespace Enforcement

April 1, 2005 — originally posted on artima.com


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!


← All Posts · ← Previous · Next →