Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Delaney, Timothy (Tim)
Guido van Rossum wrote: >> __hash__() isn't always O(1), so in my world it wouldn't be a >> property. > > I like this best of all the arguments presented so far, and consider > the case closed. > > (The weakness of the argument "but hash() can take a long time to > compute" is that a good hash

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Guido van Rossum
On 4/4/06, Giovanni Bajo <[EMAIL PROTECTED]> wrote: > Guido van Rossum <[EMAIL PROTECTED]> wrote: > > > The question is where to draw the line. I don't believe you really > > meant "all no-args methods". Perhaps you meant "all side-effect free > > argument-less methods that return the same value ea

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Giovanni Bajo
Guido van Rossum <[EMAIL PROTECTED]> wrote: > The question is where to draw the line. I don't believe you really > meant "all no-args methods". Perhaps you meant "all side-effect free > argument-less methods that return the same value each time (or at > least until some explicit change to the obje

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Greg Ewing
Delaney, Timothy (Tim) wrote: > 2. If it's a property, subclasses need to override the getter and > recreate the property if they want to change the hash of the object > (unless the base class uses a lazy property). In which case the performance advantage becomes negative (instead of just a metho

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Greg Ewing
Guido van Rossum wrote: > The __hash__() method qualifies, which is why it's a tough call (I'll > come back on that; I want to come up with a reason why __hash__() > should remain a method). Another thought is how frequently the method/attribute is going to be used. I can't even remember when was

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Greg Ewing
Barry Warsaw wrote: > 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, That sounds like a good use for Py3k-style views! -- Greg _

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Greg Ewing
Barry Warsaw wrote: > Certainly "foo.get_something()" and > "foo.set_something(thing)" are much better spelled "foo.something" and > "foo.something = thing". If you already have a get/set pair, that definitely makes sense. If hash() had been spelled get_hash() it might have made sense there too.

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Greg Ewing
Guido van Rossum wrote: > We apparently need more guidance for when it's appropriate to turn > something into an attribute. I'd suggest that things which could require substantial computation to obtain should remain methods; hash() seems to fall into that category. -- Greg __

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Delaney, Timothy (Tim)
Guido van Rossum wrote: > The __hash__() method qualifies, which is why it's a tough call (I'll > come back on that; I want to come up with a reason why __hash__() > should remain a method). The iterator-getting example above doesn't > qualify. Yeah - I felt it was a borderline case, so thought i

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Guido van Rossum
On 4/4/06, Barry Warsaw <[EMAIL PROTECTED]> wrote: > 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. Cert

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Brett Cannon
On 4/4/06, Barry Warsaw <[EMAIL PROTECTED]> wrote: > On Tue, 2006-04-04 at 09:57 -0700, Guido van Rossum wrote: > > On 4/3/06, Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote: > > > I've been thinking that `hash` could be an attribute (or property if it > > > needs to be calculated on-the-fly) rat

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Barry Warsaw
On Tue, 2006-04-04 at 09:57 -0700, Guido van Rossum wrote: > On 4/3/06, Delaney, Timothy (Tim) <[EMAIL PROTECTED]> 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

Re: [Python-3000] hash as attribute/property

2006-04-04 Thread Guido van Rossum
On 4/3/06, Delaney, Timothy (Tim) <[EMAIL PROTECTED]> 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.