The benefit of properties (was Re: PEP 8: on member variables vs. attributes)

Laura Creighton lac at strakt.com
Fri Jan 17 09:55:08 EST 2003


Peter Hansen wrote:
> 
> I rebelled against this at the time, almost outlawing properties,
> because it got to the point where I couldn't tell when something
> was just setting a value, possibly with a check or clipping or
> something applied, and when the code -- which looked like a simple
> assignment -- was actually storing some data in a file, sending
> a message to another thread, stopping the machine's motion, and 
> then launching a Space Shuttle.
> 
> No doubt forbidding them was an overreaction, but at least it
> let us start getting a handle on the complexity of the code.

> I've been looking forward to having a chance to let them redeem
> themselves when I start using them with Python... if they can.
> Do they really enhance clarity and maintenance, or might they be
> more _in the way_ of easy comprehension?

This is a judgement call based on what level of abstaction you want
for the solving of your problem.  Do you want any of your programmers
to _care_ that what really happens when a state changes is 'store some
data in a file, send a message to another thread ....'?  If their
reaction is 'we're mathematicians, don't talk to us about hardware'
then they may be absolutely correct.

Laura Creighton





More information about the Python-list mailing list