[Python-Dev] Definining properties - a use case for class decorators?
greg.ewing at canterbury.ac.nz
Tue Oct 18 03:15:45 CEST 2005
Guido van Rossum wrote:
> With decorators there was a concrete issue: the modifier trailed after
> the function body, in a real sense "hiding" from the reader.
A similar thing happens with properties, the property
definition (which is the public interface) trailing
after the accessor methods (which are an implementation
> Certainly the proposed solutions so far are worse than
> the problem.
I agree with that (except for mine, of course :-).
I still feel that the ultimate solution lies in some form
of syntactic support, although I haven't decided what
> But since you define the API, are you sure that you need properties at
> all? Maybe the users would be happy to write widget.get_foo() and
> widget.set_foo(x) instead of widget.foo or widget.foo = x?
I'm one of my main users, and I wouldn't be happy with
it. I *have* thought about this quite carefully. An early
version of the PyGUI API (predating properties) did things
that way, and people complained. After re-doing it with
properties, and getting some experience using the result,
I'm convinced that properties are the way to go for this
> To which Tim Delaney responded, "have a look at my response here:"
> I looked at that, and now I believe it's actually *better* to mention
> the property name twice, at least compared to Tim' s approach.
I'm inclined to agree. Passing functions that you're not
going to use as functions but just use the name of doesn't
And in my version, it's not *really* redundant, since the
name is only used to derive the names of the accessor methods.
It doesn't *have* to be the same as the property name, although
using anything else could justifiably be regarded as insane...
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev