Teaching Programming

Chris Rebert clp2 at rebertia.com
Tue May 4 12:11:44 EDT 2010


On Tue, May 4, 2010 at 8:49 AM, D'Arcy J.M. Cain <darcy at druid.net> wrote:
> On Wed, 5 May 2010 00:35:18 +1000
> James Mills <prologic at shortcircuit.net.au> wrote:
>> In my experience of non-indentation sensitive languages
>> such as C-class (curly braces) it's just as hard to keep track
>> of opening and closing braces.
>
> Harder.  That was the big "Aha!" for me with Python.  My first
> programming language was Fortran in 1969 so when I saw indentation as
> syntax I also recoiled in horror for about 0.5 seconds.

The amount of mental scaring that Fortran has caused regarding
indentation is astounding.
Maybe the PSF should run re-education camps for Fortran programmers... :P

> However, I
> immediately realized that from now on I could be sure that if it looked
> right then it was right.
>
>    for (x = 0; x++; x < 10);
>        printf("Current number is %d\n", x);
>
> Or...
>
>    for (x = 0; x++; x < 10);
>    {
>        printf("Current number is %d\n", x);
>    }
>
> Oops.  Looks right but isn't.  Try to make that mistake in Python.

Technically, that pitfall /could/ be eliminated if curly-braces
languages simply always required the curly-braces for bodies and
stopped special-casing the null body case, in which case both your
examples would be syntax errors. Removing the special-casing of
single-line bodies too would remove a further class of errors.
However, I've yet to encounter a language that takes such an approach.
Quite a pity.

Cheers,
Chris
--
I've thought a lot about this.
http://blog.rebertia.com/2010/01/24/of-braces-and-semicolons/



More information about the Python-list mailing list