[Python-3000] hash as attribute/property

Barry Warsaw barry at python.org
Tue Apr 4 21:39:53 CEST 2006

On Tue, 2006-04-04 at 09:57 -0700, Guido van Rossum wrote:
> On 4/3/06, Delaney, Timothy (Tim) <tdelaney at avaya.com> wrote:
> > I've been thinking that `hash` could be an attribute (or property if it
> > needs to be calculated on-the-fly) rather than the current method call.
> >
> > Or it could be an easy thing to add to the "won't change" PEP ...
> The latter, please.
> We apparently need more guidance for when it's appropriate to turn
> something into an attribute. I don't have time to write that up right
> now; if someone else can give it a shot, I'd appreciate it; or I'll
> come back to this topic later.

Just a data point.  In our API, we've been converting all of our no-arg
methods to attributes/properties, each of which may or may not be
writable of course.  It's simplified our Python code enormously, and
made it much more readable.  Certainly "foo.get_something()" and
"foo.set_something(thing)" are much better spelled "foo.something" and
"foo.something = thing".

As a general principle, we've been making this conversion for any
getters and setters that take no arguments, both for pure-Python types
and C-implemented types.  While we were at it, we changed everything
that returns a newly formed concrete sequence to returning an iterator
(which broke code that was doing random access into the sequence, but
that's another story).

I don't know whether Python 3000 wants to encourage that style, but it
works well for us.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 309 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-3000/attachments/20060404/d3c29ed8/attachment.pgp 

More information about the Python-3000 mailing list