c++ for python programmers

Nicola Musatti nicola.musatti at gmail.com
Wed Feb 14 10:45:33 EST 2007


On Feb 14, 2:41 pm, Neil Cerutti <horp... at yahoo.com> wrote:
[...]
> Don't forget the lack of standard garbage collection.

Optional garbage collection is highly likely to be included in the
next C++ standard, due out in a couple of years.

> Also there's the hell known as exception safety.
>
> Python conceptually has many of the same issues with exception
> safety, but at least memory leaks aren't one of the consequences.
> I imagine most Python programmers don't even think about
> exception safety, but probably should be. We just happily raise
> exceptions willy-nilly, without worrying about our objects
> remaining in a reasonable state. Or do we? Maybe it's better not
> to think about it. ;-)

On the other hand having everything dynamically allocated prevents the
adoption of deterministic destruction, which is a far better clean up
mechanism than try/finally clauses.

In modern C++ standard containers and smart pointers help solve most
memory related problems. I'm aware that most is not the same as all,
but on the other hand garbage collection has it's problems too:
depending on the algorithm it may not be able to reclaim all the
unreachable memory and forgetting to explicitly reset variables may
lead to hanging to memory that is really not needed anymore.

Cheers,
Nicola Musatti




More information about the Python-list mailing list