Why indentation is use to denote block of code?

Grant Edwards invalid at invalid
Mon Sep 14 00:49:50 CEST 2009

On 2009-09-13, Peng Yu <pengyu.ut at gmail.com> wrote:

> One disadvantage of using indentation to denote a block of code is
> that the runtime to automatically indent a python code would be about
> a few times more than the runtime to automatically indent a C++ code
> of the same length (both are in vim).

Talking about "automatically indenting Python" makes no sense.

It would be the equivalent of removing all the braces "{}" from
C code and then talking about automatically inserting them in
the proper places.  If you had a program that could do that,
you might as sell just have it generate all of the source code
for you from scratch.

In C, indentation is just a redundant visual clue for the
reader.  It is needed because people are really awful at
parsing block delimiters and if/then/else/while sematics

In python the indentation _is_ the block delimiters, which
means that the block structures perceived by the reader via
indentation _always_ matches the block structure seen by the
compiler.  That's not true in C, and it causes all sorts of
bugs when the structure perceived by the reader (via
indenation) doesn't match that perceived by the compiler (via

Grant Edwards                   grante             Yow! If I had a Q-TIP, I
                                  at               could prevent th' collapse
                               visi.com            of NEGOTIATIONS!!

More information about the Python-list mailing list