2.2 properties and subclasses

Miles Egan miles at rddac.com
Mon May 19 22:17:08 EDT 2003


In article <mailman.1053391949.23848.python-list at python.org>, Tim Peters wrote:
> [Miles Egan]
>> This is the behavior I was expecting.  I guess what I really want here
>> is a simple way to implement properties in the base class and
>> intercept access to them in some cases in subclasses (lazy
>> initialization, etc).
>>
>> Why don't you recommend this?  It seems like a pretty natural solution
>> to my current problem.
> 
> Just because it's clearer, and more efficient at runtime, to repeat
> 
>     prop = property(get_prop)
> 
> in both classes.  For that matter, it would be clearer and more efficient
> still to have clients call get_prop() directly and skip the property layer,
> but I appreciate that may be less convenient for clients.  The two ways of
> implementing with properties look the same to clients.

Repeating the property declaration for every property becomes painful
when you have a dozen classes with 10 properties each.  There's
already a fair amount of boilerplate you have to write to set the
properties up in the base class.

Despite the inconvenience, I'd still much rather have properties than
not.  The runtime overhead doesn't concern me much.  If I were really
worried about function call overhead I wouldn't be using a scripting
langauge.

-- 
miles egan
miles at rddac.com

reverse the domain name to find me

OpenPGP/GPG Key 0x01F53D51 @ wwwkeys.us.pgp.net




More information about the Python-list mailing list