3D graphics programmers using Python?

Alex Martelli aleax at aleax.it
Mon Feb 10 03:03:51 EST 2003


Erik Max Francis wrote:

> eichin at metacarta.com wrote:
> 
>> Interesting - I've actually found interview questions about basic STL
>> aspects (like "why might you want to avoid put objects into
>> containers"[1]) ...
> 
> Presuming that's meant to be a _putting_ there, I'm not sure I
> understand what it's getting at.  If containers aren't for putting
> objects into, what would you put in them?

Pointers or smart pointers to the objects.  STL (and the Standard
C++ Library originally inspired from it and regularly misnamed as
if it _was_ STL;-) copies objects you put into it, destroys the
copy when the container is destroyed, etc -- basically you need
objects that implement the "canonical" operations (ctor, dtor,
assignment) AND you need to be happy with copy semantics.  In the
frequent occasions where you want reference semantics instead,
you need (a modest amount of) extra work.

In Python, no problem, of course, since everything you put in
containers (etc) are (a kind of) "smart pointers", and when you
want copies you explicitly ask for copies; similarly for Java,
as it happens (reference semantics, except for some low-level
types); but, in C++, it IS an important distinction to draw.


Alex





More information about the Python-list mailing list