[Python-Dev] Definining properties - a use case for class decorators? (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Tue Oct 18 03:15:45 CEST 2005
- Previous message: [Python-Dev] Definining properties - a use case for class decorators?
- Next message: [Python-Dev] Definining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 detail).
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 yet.
But since you define the API, are you sure that you need properties at all? Maybe the users would be happy to write widget.getfoo() and widget.setfoo(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 particular application.
To which Tim Delaney responded, "have a look at my response here:" http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/408713
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 seem right.
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 +--------------------------------------+
- Previous message: [Python-Dev] Definining properties - a use case for class decorators?
- Next message: [Python-Dev] Definining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]