Protected Methods and Python

Jp Calderone exarkun at intarweb.us
Wed Apr 16 03:52:54 EDT 2003


On Wed, Apr 16, 2003 at 03:39:59AM +0000, Venkatesh Prasad Ranganath wrote:
> [snip]
> 
> All said, how do you ensure "design by interface" in Python?   If every 
> feature of a class is open to the user then he/she will use them as he/she 
> sees fit.  However, the writer of the class could have coded some methods 
> for ancillary purposes and later decides to do away with them in the next 
> version of the class.  How should the user deal with this situation?  In my 
> opinion, protected and private as in C++ or Java empowers the library 
> developer to expose just the interface that he/she intends the user to see. 
> Nothing more and nothing less.  (It's an issue dealing with abstraction.)  
> As a result, the user can be more care-free while using the library code as 
> he cannot screw up the internals if the library code doesn't do it on it's 
> own.  On the other hand, if all members of a class are visible to the user 
> then the user needs to be more diligent while using the library.  I prefer 
> the first option.

  If it isn't documented, don't use it :)  You have a point though.  Some
libraries don't make it clear what is public and what is an implementation
detail.  What's the worst case, though?  You upgrade, your software breaks,
you downgrade, it works again, and maybe you fire off an unhappy email to
the dev list for the library.

> 
> On the issue of working around bugs in a library via runtime protected 
> attributes, it would be better if the skillful coder fixed the bug ;-) or 
> use another library.  This is just what I would do.

  Good point.  I omitted this possibility in hopes of keeping the point
clear, but it's what I try to do as well :)

  Jp

--
 up 27 days, 3:02, 3 users, load average: 1.45, 1.42, 1.43





More information about the Python-list mailing list