Automatic Generation of Python Class Files

Steven Bethard steven.bethard at gmail.com
Tue Oct 23 16:39:39 EDT 2007


Bruno Desthuilliers wrote:
>> I guess as long as your documentation is clear about which attributes 
>> require computation and which don't...
> 
> Why should it ? FWIW, I mentionned that I would obviously not use 
> properties for values requiring heavy, non cachable computation. This 
> set aside, the fact that the attribute is computed (or not) is none of 
> the concerns of client code. I think you know that concept, it's called 
> 'encapsulation' !-)

Encapsulation doesn't mean having no understanding of the object you're 
using.  We all use Python lists, knowing that adding to the end is 
cheap, and adding to the front is expensive.  If you're using someone's 
data type, but you have no idea where the performance costs are, you're 
just asking for trouble.  That's true even if you're not prematurely 
optimizing -- in the case of lists, doing the wrong sort of insert can 
make an O(N) algorithm an O(N**2) algorithm. So I don't think this has 
anything to do with encapsulation.

This really only has to do with what you and I think are natural 
programming intuitions. I agree that Python is not Java, or C, or 
whatever, but there are a wide variety of precedents in a wide variety 
of languages (the Python stdlib included) that lead many programmers to 
expect only minimal computation to be performed when accessing 
attributes. I believe we simply disagree on whether or not Python 
programmers need to be trained out of these expectations.

STeVe



More information about the Python-list mailing list