Will python never intend to support private, protected and public?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Thu Sep 29 11:41:40 EDT 2005


On Thu, 29 Sep 2005 18:29:36 +0400, en.karpachov wrote:

> On Fri, 30 Sep 2005 00:16:02 +1000
> Steven D'Aprano wrote:
> 
>> Say you have written a class, with a private variable. I decide that I
>> need access to that variable, for reasons you never foresaw.
> 
> What if the access to that variable was forbidden for reasons you never
> foresaw? What if the class author decide to remove the variable in the next
> version of the class, because it's not an interface, but only a part of the
> class implementation?

I either write buggy code that breaks when the class author changes the
variable, or I write code that is careful, does not make assumptions about
the nature of the variable, and fails gracefully when the author changes
or removes the variable.

In the first case, I'm responsible for the bug, and will hang my head in
shame. In the second case, I impress people with the quality of my code
and get surrounded by hundreds of adoring women who want to have my
children. (Well I can dream can't I?)

But either way, the original class author may never remove the variable,
in which case I have all the advantages of accessing that semi-private
variable with none of the disadvantages.

This, of course, assumes that there are some advantages of accessing the
variable. If there are none, then I would be foolish to make a rod for my
own back by bypassing the class author's supported API for no benefit.


>> What happens
>> next? I ask you nicely to please change your class and turn that private
>> attribute into a public one. What happens if you refuse? Can I have you
>> taken out and shot and seize ownership of your class, or do I have to
>> copy and paste your class into my code, creating a duplicate class I can
>> modify as much as I like?
> 
> Yes, that's how it works in the open source. 

Oh please, it does not. We hardly ever have people taken out and shot so
we can take their code. That's more Microsoft's way of doing business...

*wink*

> What's wrong with it? You
> don't need _this_ class, because it's functionality doesn't fit to you. So
> you take the source code and write another class, doing exactly what you
> want it to do.

Perhaps I don't have access to the source code at all, only the .pyc file,
but I've learnt the secret name of the private attribute from the book
"Undocumented Tricks And Tips For Pythonistas".

Or I do have access to the source code, but under a licence that does not
allow me to legally modify the code and distribute it. Should I break the
law and risk a civil suit or even jail for copyright infringement?

Or maybe I just don't feel like taking on the responsibility of
maintaining the entire class, but feel that it is perfectly within my
capabilities to update my code if and when one specific private variable
gets modified or removed.

Or maybe I just don't like the idea of introducing bugs and duplicating
labour by copying and pasting code.


-- 
Steven.




More information about the Python-list mailing list