Your beloved python features

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Feb 6 00:01:46 CET 2010


On Fri, 05 Feb 2010 15:22:25 -0600, Bruce C. Baker wrote:

> GvR got it right when he discarded the superfluous semicolons from the
> ends of statements--and then he ADDS superfluous colons to the ends of
> control statements? 

They're not superfluous, they have a real, practical use.


> It will probably be as much of a shock to you as it
> was to me when I learned after studying parsing that colons, semicolons,
> "then"'s and "do"'s, etc.,  are simply noise tokens that serve no
> purpose except to clutter up the source.

Incorrect, they do have a use. Hint: source code isn't just read by 
parsers.



> As for enforced indentation, back in the late 60's when I was a
> programming newbie I remember thinking how cool it would be to just
> indent the statements controlled by for loops (we didn't have none of
> them fancy while loops in FORTRAN back then! :-) )  Not too long after
> that I saw the havoc that a buggy editor could wreak on nicely-formatted
> source. :-( 

As opposed to how resistant source code is to buggy editors that make 
other changes to source code.

If your editor flips the order of characters, or turns the digit "4" into 
"7", or deletes braces, or inserts "#" characters at the start of lines, 
you would dump the editor in a second. But if the editor inserts or 
removes whitespace, we're supposed to continue using the editor and 
change the language?


> Formatting held hostage to a significant, invisible
> whitespace char? 

It's not invisible. You can see it by noticing the space between the left 
margin and the start of non-whitespace text. Can you see the difference 
between these?

hello world

    hello world

Of course you can, unless your News reader or mail client is buggy. If it 
is deleting whitespace at the start of lines, how can you trust it not to 
delete anything else?

Trailing spaces and tabs, on the other hand, *are* invisible. But they're 
also insignificant, and so don't matter.

(Except for one little tiny corner case, which I shall leave as an 
exercise for the advanced reader.)



-- 
Steven



More information about the Python-list mailing list