Preventing execution of a method

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Dec 11 14:48:49 EST 2008


Emanuele D'Arrigo a écrit :
> Thank you all for the confirmation and the suggestions (including the
> tangential ones: I didn't know one could remove your his own posts!).
> 
> As much as I really like Python (which I've been using full-time only
> for the past two months) I really wish it did have regular private/
> protected/public methods.

What for ? What you need is a way to tell the client code what's part of 
the interface and what's implementation detail. From experience (*years* 
fo experience), no one in it's own mind will mess with implementation 
unless he has a very compelling reason _and_ is willing to pay the price 
("shit, I broke everything... Ok, my fault.")

> I'm building an application that can be extended by the users and I
> really wish there was a solid way to prevent them from accessing parts
> of the application that they shouldn't   access

In Python, "shouldn't access" is spelled with a single leading 
underscore !-)

> or to provide read-only
> access. I.e. right now I'm working on the graphical client which
> potentially could be rewritten entirely by the users. It is necessary
> and perfectly reasonable for the client module to access some of the
> objects to be represented graphically, but those objects shouldn't be
> modifiable by it.

Why so ? At worst, they'll break everything. So what ? As long as they 
mess with your implementation, they are responsible for what happens. 
OTHO, someone may have a perfectly valid reason to rewrite parts (or 
whole) of your GUI - and he'll just love you for not standing in the way.

> I now wonder, would developing the graphical client as an entirely
> separate application, communicating with the server via the localhost
> network interface and messages, solve the problem?

*which* problem ? Seriously ? What do you fear ? Extension code breaking 
your app ? How is that *your* problem (I mean, as long as you 
explicitely told the user what was part of the API and what wasn't ?).

What if your program was written in C, distributed only as compiled 
machine code, and one of your users decided to make random edits in the 
binary code ? Would you feel responsible ? *Nothing* in this world is 
idiot-proof, so don't waste time trying to protect idiots from themselves.




More information about the Python-list mailing list