Re: [Q]: Syntax For Blocks Probable?

Guido.van.Rossum@cwi.nl
Fri, 06 May 1994 00:38:25 +0200

> But: I dislike the fact that blocks of statements are not enclosed by
> balanced parentheses (or something like that), and that statements are
> terminated by a newline.
> Awk did that better, IMO, because no particular formating of the code
> is imposed.
> Any chance that that will be changed in the future?

Sorry for not responding earlier. I did see your message but hoped
that someone else would explain my point of view to you :-).

This question pops up on the list at least several times a year. Last
time, Tim Peters said (from memory) that most people learn to love
this feature after a while.

Basically I believe that using indentation for grouping is extremely
elegant and contributes a lot to the clarity of the average Python
program. Some arguments for it:

- Since there are no begin/end brackets there cannot be a disagreement
between grouping perceived by the parser and the human reader. I
remember long ago seeing a C fragment like this:

if (x <= y)
x++;
y--;
z++;

and staring a long time at it wondering why y was being decremented
even for x > y... (And I wasn't a C newbie then either.)

- Since there are no begin/end brackets there can be no conflicting
coding styles. In C there are loads of different ways to place the
braces (including the choice whether to place braces around single
statements in certain cases, for consistency). If you're used to
reading (and writing) code that uses one style, you will feel at least
slightly uneasy when reading (or being required to write) another
style.

- Many coding styles place begin/end brackets on a line by themself.
This makes programs considerably longer and wastes valuable screen
space, making it harder to get a good overview over a program.
Ideally, a function should fit on one basic tty screen (say, 20
lines). 20 lines of Python are worth a LOT more than 20 lines of C.
This is not solely due to the lack of begin/end brackets (the lack of
declarations also helps, and the powerful operations of course), but
it certainly helps!

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>