whitespace denotation - rebuttal

Shae Erisson shapr at uab.edu
Sat Jun 17 07:52:29 EDT 2000


"Thaddeus L. Olczyk" wrote:
> 
> After using Python for a while I've come to the conclusion that
> using whitespaces to determine the begining and ending of blocks
> is bad for three reasons.
<snip>
> By having
> the code depend on indentation, and the editor do the indentation
> for you, you give the editor responsiblity in how the code will flow.

I am an advocate for specific indentation as a requirement.
Also, typing backspace or tab allows you to change the indentation,
so... No. My editor does not have complete control over my code flow.

> 1) The first is rather stylistic and may not appeal to most, but I
> have often found it useful. When debugging code I often put in
> code to help me figure out whats happening. I also avoid indenting
> such code so that it easy to remember where it is later when I want to
> take it out. An example ( assuming I use begin and end to denote
> blocks ):
<snippage>
> You can immediately see code that you used for debugging and remove
> it. However right now writing code that way makes it illegal.

You should read up on the -O command line switch for the Python
interpreter. It allows you to do at least two quite spiffy things that I
know of:
First, assert statements are compiled right out.
Second, any "if __debug__:" statements are compiled right out as well.
This means there is a better way to do debug code in python that even
allows conditional compilation of that code.
(random note: the -v command line switch can also be quite fun, but for
completely unrelated reasons)

> Initially the line in error was indented correctly, but someplace
> along the line the extra tab was introduced. A lot of effort then had
> to go in to finding this bug. With begin...end or braces this is less
> likely to happen.

Unit testing can really make your life easier, no matter what language
you use. Check out http://pyunit.sourceforge.net
PyUnit is great, thanks to Steve Purcell.
You may also want to take advantage of tabnanny and friends to check
your files for inconsistent indentation.

> 3) Finally. Python is a language where it is almost easy to write
> extensible programs. To illistrate what I mean consider this example
> of a python program I recently wrote:
> There is a C++ project which involves many project files and workspace
> files 

This looks like a C++ problem to me. How does this apply to Python?

> That
> means that I have to reindent the block. So as I reindent I have to
> try to remember how the indenting went. Something I stink at.

Try IDLE. Ctrl-] indents the entire block you have selected, Ctrl-[
dedents it.
It's quite easy.
PythonWin has an option to check/display all or illegal whitespace, and
both IDLE and PythonWin allow Tabify and Untabify. (convert spaces to
tabs and back, your choice of # of spaces per tab).

In conclusion, I don't think Python is for everybody, but it is for me.
If you like begin and end statements and you don't like whitespace,
Ruby, Rebol or J may be more your style.
On the other hand, I think you might like Python more if you check out
some of the nifty bits I've mentioned. Seriously, I'd like to help if I
can.
-- 
sHae mAtijs eRisson (sHae at wEbwitchEs.coM) gEnius fOr hIre
 squirrels furnished by Paul E Black, the world is safe.



More information about the Python-list mailing list