Python design philosophy

Paul Prescod paul at prescod.net
Wed Jun 28 20:13:35 EDT 2000


Steve Juranich wrote:
> 
> I am *brand* new to python (as of Sunday), and I just got to the section
> in the tutorial about classes.  I was wondering why there really isn't
> such an idea as a "private" member of classes?  I understand that members
> can be hidden, but not really protected from the user.  I was wondering
> what the benefit of this would be?  Wouldn't it open the possibility of
> security holes?  

Private methods cannot really be used for security purposes. In any
decent language there is a way around the private declaration. In Java
it is reflection. In C++ it is pointer manipulation. Python says: "Why
pretend to provide security that isn't really there?"

> Also, what benefit is gained by allowing a user to
> add/delete members from existing classes?  Wouldn't it be more desirable
> to create his/her own derived class?

It's sometimes useful and more effort to prevent than allow. Consider a
set of objects that you are trying to serialize to disk. You must attach
a flag to in order to say "they've been processed." You can't always
inherit because you aren't trying to make new objects -- you're trying
to change existing objects.
-- 
 Paul Prescod - Not encumbered by corporate consensus
The calculus and the rich body of mathematical analysis to which it 
gave rise made modern science possible, but it was the algorithm that 
made the modern world possible.
	- The Advent of the Algorithm (pending), by David Berlinski





More information about the Python-list mailing list