Python Rocks!

William Tanksley wtanksle at hawking.armored.net
Thu Jan 20 00:04:46 EST 2000


On Wed, 19 Jan 2000 11:48:20 -0800, tye4 wrote:
>Hans-Joachim Widmaier <hjwidmai at foxboro.com> wrote in message

>> 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.

As a matter of fact, it's not at all error-prone -- it's simply an
outright error.  Python won't accept that source code (and not only
because it's actually C); the indentation is not just error-prone, it's
ambiguous.  The else isn't in a sane location; nobody but the original
programmer can tell where it was supposed to be.

In C the above code would not cause an error, but would instead be
error-prone.

>There is not single programming language that forces such a bizarre
>indentation rule.

Yes, there is -- Python.

>If thousands of programmers have a problem with this, why isn't it fixed.

We _did_ have a problem with it.  That's why we chose Python, because it
fixed the problem.

>The solution is backward compatible:
>if x = 5:
>    print 'x is 5'
>end if

If you state that particular lie often enough, does that make it true?
Here's a counterexample:

end = 0
if x == 5:
   end = 1
   print 'x is 5'
print end

Surely even you can see the problem.

>-tye4

-- 
-William "Billy" Tanksley, in hoc signo hack



More information about the Python-list mailing list