Experiences/guidance on teaching Python as a first programming language

Chris Angelico rosuav at gmail.com
Thu Dec 19 15:51:16 EST 2013


On Fri, Dec 20, 2013 at 7:42 AM, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> A piece of code such as
>
>    for (i = 0; i < numThings; i++)
>       total[i] += things[i];
>
> is NOT improved by rewriting it as
>
>    for (theLoopIndex = 0; theLoopIndex < numThings; theLoopIndex++)
>       total[theLoopIndex] += things[theLoopIndex];
>
> Quite the reverse, IMO.

Wholeheartedly agreed. The only improvement I would make would be to
declare i in the if block (valid in C++ and some of the more recent C
standards), to emphasize the locality of the variable.

ChrisA



More information about the Python-list mailing list