Whitespace as syntax (was Re: Python Rocks!)

Skip Montanaro skip at mojam.com
Thu Feb 10 02:30:55 CET 2000

    David> ... but as someone who in the past has occasionally wasted an
    David> hour trying to fix a broken makefile because of some tab/space
    David> mixup, I'm staying vigilent.

That's a somewhat different problem.  In make tabs and spaces are indeed
treated differently.  Where a tab is needed, a space won't do at all.

    David> So my point is that what is needed is not religious wars but
    David> advice from the experienced on how they avoid the pitfalls and
    David> continuing refinement in the programming tools that keep us
    David> programmers from having to worry about these things.

Two suggestions:

    1. Use CVS, sccs, RCS or some similar tool to manage your source code.
       That gives you a benchmark against which to check your code.  In the
       six years I've been using Python, I've only needed to correct
       indentation botches a couple of times.  If you use Emacs, I recommend
       you look at ediff-revision as an excellent way to compare a file's
       current version with earlier revisions.

    2. Use python-mode (in Emacs/XEmacs) if you don't already.  Other text
       editors (vim, BBedit, Alpha, etc.) have support for indenting blocks
       of code automatically.  Search the archives for your favorites.  I
       assume Emacs+python-mode in what follows.

       Select the block you want to reindent, then use C-c > or C-c < to
       rigidly change the indentation of the selected block.  This works
       well with pasted blocks as well.  When you paste a block of text into
       the midst of another block, simply hit C-x C-x to reselect the region
       (I use XEmacs, which doesn't automatically select yanked text - GNU
       Emacs may not require this), then hit C-c > or C-c < as required to
       get that block of text to line up properly with the surrounding code.
       (Internally, it should already be correct unless there was a problem
       with it before the cut.)

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
"Languages that change by catering to the tastes of non-users tend not to do
so well." - Doug Landauer

More information about the Python-list mailing list