Python Rocks!

tye4 tye4 at yahoo.com
Wed Jan 19 14:48:20 EST 2000




Hans-Joachim Widmaier <hjwidmai at foxboro.com> wrote in message > Accidently
add or delete a space on a line? To me, it looks like you're looking
> at it the wrong way: The whitespace in front of the line isn't "spaces"
and "tabs",
> it's *indentation*. And it's added und deleted not by hitting <BackSpace>
or <Del>
>
> Every sane programmer indents his or her programs anyway. And all the C
programmers
> I know were bitten by this old example:
>
>   if (a > 3)
>     if (b == 4)
>        c = 2;
>   else
>     c = 3;
>

Perfect example.
   if (a > 3)
     if (b == 4)
        c = 2;
    else
     c = 3;

If you add a space, the 'else' will belong to the inner 'if'. If you delete
one, the 'else' will belong to the outer one. Highly error prone.

> Indentation is a way to show the structure of a program to the human
reader.
> Why do we need a second way to show it to the compiler/interpreter? This
only
> makes the code ambiguos. What was the programmer's intention in the
example
> above?
> I see the structuring by indentation as one of python's strongest points.
>
Don't get me wrong. Indentation tremendously improves readability. However,
it should not be part of the language. That way, we don't have to put an
immense amount of effort just trying get everything into the right block.
There is not single programming language that forces such a bizarre
indentation rule.
If thousands of programmers have a problem with this, why isn't it fixed.
The solution is backward compatible:
if x = 5:
    print 'x is 5'
end if

-tye4





More information about the Python-list mailing list