Newbie Q: Class Privacy (or lack of)

Antoon Pardon apardon at forel.vub.ac.be
Wed Aug 2 13:42:49 EDT 2006


On 2006-08-02, Diez B. Roggisch <deets at nospam.web.de> wrote:
>> I find that a strange purpose because when you are working on a class,
>> you don't necessarily know if you will ever know many instance of that
>> class. So should I use __slots__ in all my classes, just to be sure
>> for when someone wants many instances of one?
>  
> I find that a strange reasoning because when you are working on a class,
> you don't necessarily know if you will ever know if it needs a
> __getitem__-method.
> So do you use __getitem__ in all your classes, just to be sure
> for when someone wants __getitem__ in one?

That is IMO a totally different issue. The __getitem__ decision is an
API decision. That is normally somthing the implementor decides.

However it is the user of a class that decides how many instances
he needs of that class. 

> To my experience programming often means that requirements change - and one
> has to adapt.

Who has to adapt? The user or the writer of the class? If I'm using
a class written by someone, I sure wouldn't like to have to go
through it because of memory issues.

> If memory becomes an issue, you might overcome it using
> slots. Or a disk cache. Or buy new memory. Does that imply for you that you
> buy new disks and memory each time you start coding?

I would think that someone writing a class, shouldn't have his instances
use more memory than they need.

-- 
Antoon Pardon



More information about the Python-list mailing list