Re: [Python-Dev] defaultdict and on_missing()

2006-03-02 Thread Aahz
On Thu, Mar 02, 2006, Guido van Rossum wrote: > On 3/2/06, Barry Warsaw <[EMAIL PROTECTED]> wrote: >> On Thu, 2006-03-02 at 07:26 -0800, Aahz wrote: >>> >>> OTOH, my personal style is to always use re.compile() because I can >>> never remember the order of arguments for re.match()/re.search(). >> >

Re: [Python-Dev] defaultdict and on_missing()

2006-03-02 Thread Bill Janssen
> For an example of methods gone horribly wrong, look at Java, where you > have .length, String.length(), and Collection.size(). > Give me len() any day. I believe Ruby has similar confusing diversity > for looping (each/forEach). But Java is plagued with the same disease that hit Modula-3, distru

Re: [Python-Dev] defaultdict and on_missing()

2006-03-02 Thread Guido van Rossum
On 3/2/06, Barry Warsaw <[EMAIL PROTECTED]> wrote: > On Thu, 2006-03-02 at 07:26 -0800, Aahz wrote: > > OTOH, my personal style is to always use re.compile() because I can > > never remember the order of arguments for re.match()/re.search(). > > Agreed. I don't have that problem, because the order

Re: [Python-Dev] defaultdict and on_missing()

2006-03-02 Thread Barry Warsaw
On Thu, 2006-03-02 at 07:26 -0800, Aahz wrote: > On Wed, Mar 01, 2006, Guido van Rossum wrote: > > > > Operations with two or more arguments are often better expressed as > > function calls -- for example, map() and filter() don't make much > > sense as methods on callables or sequences. > > OTOH,

Re: [Python-Dev] defaultdict and on_missing()

2006-03-02 Thread Aahz
On Wed, Mar 01, 2006, Guido van Rossum wrote: > > Operations with two or more arguments are often better expressed as > function calls -- for example, map() and filter() don't make much > sense as methods on callables or sequences. OTOH, my personal style is to always use re.compile() because I ca

Re: [Python-Dev] defaultdict and on_missing()

2006-03-01 Thread Greg Ewing
Guido van Rossum wrote: > str.join() is an interesting case... > Making it a > string method is arguably the right thing to do, since this operation > only makes sense for strings. > The type of such a polymorphic function is easily specified: > join(sequence[T], T) -> T, where T is a string-

Re: [Python-Dev] defaultdict and on_missing()

2006-03-01 Thread Guido van Rossum
On 3/1/06, Brett Cannon <[EMAIL PROTECTED]> wrote: > But moving over to more attributes for how we access basic interfaces > seems great to me. We shouldn't approach this as "methods good, functions bad" -- nor the opposite, for that matter. When all things are equal, I'd much rather do usability

Re: [Python-Dev] defaultdict and on_missing()

2006-03-01 Thread Brett Cannon
On 2/28/06, Terry Reedy <[EMAIL PROTECTED]> wrote: > > "Greg Ewing" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > And you don't think there are many different > > types of iterables? You might as well argue > > that we don't need len() because it "only > > applies to sequences".

Re: [Python-Dev] defaultdict and on_missing()

2006-02-28 Thread Terry Reedy
"Greg Ewing" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > And you don't think there are many different > types of iterables? You might as well argue > that we don't need len() because it "only > applies to sequences". Since you mention it..., many people *have* asked on c.l.p wh

Re: [Python-Dev] defaultdict and on_missing()

2006-02-28 Thread Greg Ewing
Raymond Hettinger wrote: > -1 on the silly renaming to __next__ and adding __builtin__.next(). > We have len() because it applies to many different object types. > In contrast, next() would apply only to iterables. And you don't think there are many different types of iterables? You might as well

Re: [Python-Dev] defaultdict and on_missing()

2006-02-28 Thread Raymond Hettinger
[Greg Ewing] > I'd still like to see next(x) / x.__next__() in > some form in 3.0 for the sake of consistency, > though. +1 on modifying next() in Py3.0 to accept the send argument. -1 on the silly renaming to __next__ and adding __builtin__.next(). We have len() because it applies to many differ

Re: [Python-Dev] defaultdict and on_missing()

2006-02-28 Thread Greg Ewing
Guido van Rossum wrote: > On 2/28/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > > > PEP 342 opted to extend the generator API instead (using "send") and leave > > the > > iterator protocol alone for the time being. > > One of the main reasons for this was the backwards compatibility > problems at

Re: [Python-Dev] defaultdict and on_missing()

2006-02-28 Thread Guido van Rossum
On 2/28/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Greg Ewing wrote: > > Nick Coghlan wrote: > > > >> I wouldn't mind seeing one of the early ideas from PEP 340 being > >> resurrected some day, such that the signature for the special method > >> was "__next__(self, input)" and for the builtin "n

Re: [Python-Dev] defaultdict and on_missing()

2006-02-28 Thread Nick Coghlan
Greg Ewing wrote: > Nick Coghlan wrote: > >> I wouldn't mind seeing one of the early ideas from PEP 340 being >> resurrected some day, such that the signature for the special method >> was "__next__(self, input)" and for the builtin "next(iterator, >> input=None)" > > Aren't we getting an argu

Re: [Python-Dev] defaultdict and on_missing()

2006-02-27 Thread Greg Ewing
Nick Coghlan wrote: > I wouldn't mind seeing one of the early ideas from PEP 340 being resurrected > some day, such that the signature for the special method was "__next__(self, > input)" and for the builtin "next(iterator, input=None)" Aren't we getting an argument to next() anyway? Or was tha

Re: [Python-Dev] defaultdict and on_missing()

2006-02-27 Thread Guido van Rossum
On 2/27/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > I wouldn't mind seeing one of the early ideas from PEP 340 being resurrected > some day, such that the signature for the special method was "__next__(self, > input)" and for the builtin "next(iterator, input=None)" > > That would go hand in hand

Re: [Python-Dev] defaultdict and on_missing()

2006-02-27 Thread Nick Coghlan
Greg Ewing wrote: > Raymond Hettinger wrote: >> Code that >> uses next() is more understandable, friendly, and readable without the >> walls of underscores. > > There wouldn't be any walls of underscores, because > >y = x.next() > > would become > >y = next(x) > > The only time you w

Re: [Python-Dev] defaultdict and on_missing()

2006-02-25 Thread Guido van Rossum
FWIW this has now been checked in. Enjoy! --Guido On 2/23/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: > On 2/22/06, Michael Chermside <[EMAIL PROTECTED]> wrote: > > A minor related point about on_missing(): > > > > Haven't we learned from regrets over the .next() method of iterators > > that

Re: [Python-Dev] defaultdict and on_missing()

2006-02-24 Thread Greg Ewing
Raymond Hettinger wrote: > Code that > uses next() is more understandable, friendly, and readable without the > walls of underscores. There wouldn't be any walls of underscores, because y = x.next() would become y = next(x) The only time you would need to write underscores is when defi

Re: [Python-Dev] defaultdict and on_missing()

2006-02-24 Thread Alex Martelli
On 2/24/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > Michael Chermside wrote: > >> The next() method of iterators was an interesting > >> object lesson. ... Since it was sometimes invoked by name > >> and sometimes by special mechanism, the choice was to use the > >> unadorned name, but lat

Re: [Python-Dev] defaultdict and on_missing()

2006-02-24 Thread Raymond Hettinger
> Michael Chermside wrote: >> The next() method of iterators was an interesting >> object lesson. ... Since it was sometimes invoked by name >> and sometimes by special mechanism, the choice was to use the >> unadorned name, but later experience showed that it would have been >> better the other wa

Re: [Python-Dev] defaultdict and on_missing()

2006-02-23 Thread Greg Ewing
Thomas Wouters wrote: > __methods__ are methods that should only be > called 'magically', or by the object itself. > 'next' has quite a few usecases where it's > desireable to call it directly That's why the proposal to replace .next() with .__next__() comes along with a function next(obj) whic

Re: [Python-Dev] defaultdict and on_missing()

2006-02-23 Thread Greg Ewing
Michael Chermside wrote: > The next() method of iterators was an interesting > object lesson. ... Since it was sometimes invoked by name > and sometimes by special mechanism, the choice was to use the > unadorned name, but later experience showed that it would have been > better the other way. Any

Re: [Python-Dev] defaultdict and on_missing()

2006-02-23 Thread Michael Chermside
Walter Dörwald writes: > I always thought that __magic__ method calls are done by Python on > objects it doesn't know about. The special method name ensures that it > is indeed the protocol Python is talking about, not some random method > (with next() being the exception). In the defaultdict case

Re: [Python-Dev] defaultdict and on_missing()

2006-02-23 Thread Walter Dörwald
Guido van Rossum wrote: > On 2/22/06, Michael Chermside <[EMAIL PROTECTED]> wrote: >> A minor related point about on_missing(): >> >> Haven't we learned from regrets over the .next() method of iterators >> that all "magically" invoked methods should be named using the __xxx__ >> pattern? Shouldn't

Re: [Python-Dev] defaultdict and on_missing()

2006-02-23 Thread Thomas Wouters
On Wed, Feb 22, 2006 at 01:13:28PM -0800, Michael Chermside wrote: > Haven't we learned from regrets over the .next() method of iterators > that all "magically" invoked methods should be named using the __xxx__ > pattern? Shouldn't it be named __on_missing__() instead? I agree that on_missing sho

Re: [Python-Dev] defaultdict and on_missing()

2006-02-23 Thread Guido van Rossum
On 2/22/06, Michael Chermside <[EMAIL PROTECTED]> wrote: > A minor related point about on_missing(): > > Haven't we learned from regrets over the .next() method of iterators > that all "magically" invoked methods should be named using the __xxx__ > pattern? Shouldn't it be named __on_missing__() in

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Michael Chermside
A minor related point about on_missing(): Haven't we learned from regrets over the .next() method of iterators that all "magically" invoked methods should be named using the __xxx__ pattern? Shouldn't it be named __on_missing__() instead? -- Michael Chermside

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Edward C. Jones
Guido van Rossen wrote: > I think the pattern hasn't been commonly known; people have been > struggling with setdefault() all these years. I use setdefault _only_ to speed up the following code pattern: if akey not in somedict: somedict[akey] = list() somedict[akey].append(avalue) These lin

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Guido van Rossum
On 2/22/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > [Guido van Rossum"] > > If we removed on_missing() from dict, we'd have to override > > __getitem__ in defaultdict (regardless of whether we give > >defaultdict an on_missing() hook or in-line it). > > You have another option. Keep your cu

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Raymond Hettinger
[Guido van Rossum"] > If we removed on_missing() from dict, we'd have to override > __getitem__ in defaultdict (regardless of whether we give >defaultdict an on_missing() hook or in-line it). You have another option. Keep your current modifications to dict.__getitem__ but do not include dict.on_m

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Guido van Rossum
On 2/22/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > I'm concerned that the on_missing() part of the proposal is gratuitous. The > main use cases for defaultdict have a simple factory that supplies a zero, > empty list, or empty set. The on_missing() hook is only there to support > the rare

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Greg Ewing
Raymond Hettinger wrote: > I'm concerned that the on_missing() part of the proposal is gratuitous. I second all that. A clear case of YAGNI. -- Greg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev U

Re: [Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Fredrik Lundh
Raymond Hettinger wrote: > Aside: Why on_missing() is an oddball among dict methods. When > teaching dicts to beginner, all the methods are easily explainable ex- > cept this one. You don't call this method directly, you only use it > when subclassing, you have to override it to do anything use

[Python-Dev] defaultdict and on_missing()

2006-02-22 Thread Raymond Hettinger
I'm concerned that the on_missing() part of the proposal is gratuitous.  The main use cases for defaultdict have a simple factory that supplies a zero, empty list, or empty set.  The on_missing() hook is only there to support the rarer case of needing a key to compute a default value.  The h