Experiences/guidance on teaching Python as a first programming language

Chris Angelico rosuav at gmail.com
Wed Dec 18 04:01:52 CET 2013

On Wed, Dec 18, 2013 at 1:33 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
> On Tue, Dec 17, 2013 at 4:32 PM, Roy Smith <roy at panix.com> wrote:
>> There's very few mysteries in C.  You never have to wonder what the
>> lifetime of an object is
> Yes you do. Lifetimes are hard, because you need to malloc a lot, and
> there is no defined lifetime for pointers -- they could last for just
> the lifetime of a stack frame, or until the end of the program, or
> anywhere in-between, and it's impossible to know for sure, and if you
> get it wrong your program crashes. So there's all these conventions
> you have to come up with like "borrowing" and "owning", but they
> aren't compiler-enforced, so you still have to figure it out, and you
> will get it wrong. Successors like C++ mitigate these issues with
> destructors (allowing heap-allocated stuff to be tied to the lifetime
> of a stack), and smart pointers and so on.

Wrong. A pointer is a scalar value, usually some kind of integer, and
its lifetime is the same as any other scalar. Heap memory's lifetime
is also very simple: it lasts until freed. (Though technically that's
not even a part of the language - malloc/free are just functions. Not
that it matters. Anyway, C++ has the new and delete operators, which
are part of the language.) There are conventions to prevent memory
leaks, but those are mere conventions. It's simple in the same way
that a toy electric motor is simple: you apply current to it, and it
spins. There's so little that it can do that it HAS to be simple.


More information about the Python-list mailing list