Experiences/guidance on teaching Python as a first programming language

Chris Angelico rosuav at gmail.com
Wed Dec 18 04:24:06 CET 2013


On Wed, Dec 18, 2013 at 2:12 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
>> Wrong. A pointer is a scalar value, usually some kind of integer, and
>> its lifetime is the same as any other scalar.
>
> The duration of a pointer's validity is far more interesting, and that
> is why it is the primary meaning of the term "pointer lifetime". Also,
> it's obviously what I meant.
>>  Heap memory's lifetime
>> is also very simple: it lasts until freed.
>
> Sometimes simple things are hard to use correctly. I only said it was
> hard, not complicated.

Sure, which is why I went on to discuss the block of memory pointed
to. But the rules are a lot simpler than in Python, where something
exists until... uhh... the system feels like disposing of it. At which
point __del__ will probably be called, but we can't be sure of that.
All we know about an object's lifetime in Python is that it will
continue to live so long as we're using it. And then multiprocessing
and fork make it messier, but that's true in any language.

The original point was that C has no mysteries. I posit that this is
true because C's rules are so simple. It might well be harder to work
in this system (taking it to an extreme, Brainf* is about the simplest
Turing-complete language possible, and it's virtually impossible to
write good code in it), but it has no mysteries.

ChrisA



More information about the Python-list mailing list