[Python-3000] hash as attribute/property
brett at python.org
Tue Apr 4 21:48:43 CEST 2006
On 4/4/06, Barry Warsaw <barry at python.org> wrote:
> 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".
I would amend that to anything that does not cause mutation when
calling (this does not include creating new objects, though) or mutate
other things when assigning (thanks to properties that is possible).
Basically that is my personal rule of thumb for when I code.
> 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.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v18.104.22.168 (GNU/Linux)
> -----END PGP SIGNATURE-----
> Python-3000 mailing list
> Python-3000 at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/brett%40python.org
More information about the Python-3000