Brandon Craig Rhodes wrote:
Tres Seaver <[EMAIL PROTECTED]> writes:
Martijn Faassen wrote:
IFoo.adapt() for normal adaptation
IFoo.multiadapt() for multi adaptation
I'd rather have 'adapt' take *args for the contexts, and keywords
for extras (like name).
And you could make the "default=" another possible extra! In which
case our proposals at the moment compare something like this:
Single adaptation IFoo(a)
... with default IFoo(a, default=y)
Multi adaptation IFoo(multi=(a,b))
... with default IFoo(multi=(a,b), default=y)
Named multi adapter IFoo(multi=(a,b), name='z')
... with default IFoo(multi=(a,b), name='z', default=y)
This syntax is pretty comfortable because you get code completion for
free if you are using an ide (ex. eclipse pydev).
At the moment IFoo() invokes the factory of an object (if registered).
IMO the current implementation is a miss-feature because you can't
assign any parameters. I would prefer that IFoo() does look up the
default utility and IFoo(name='z') the named one.
But this change could break existing code.
Single adaptation IFoo.adapt(a)
... with default IFoo.adapt(a, default=y)
Multi adaptation IFoo.adapt(a,b)
... with default IFoo.adapt(a,b, default=y)
Named multi adapter IFoo.adapt(a,b, name='z')
... with default IFoo.adapt(a,b, name='z', default=y)
Well, I have to admit, yours are a lot prettier. The word "adapt"
takes no more characters than my "multi", and parenthesis disappear!
And though I might quibble that "adapt()" would be better spelled
"utility()", there is a nice symmetry about your idea.
- Both patterns make it explicit to anyone reading the code when a
default value is being passed, which should vastly reduce surprise.
- Mine feels more natural and Pythonic to people who, like PvW in his
book, think of adaptation as being like casting.
Perse Engineering GmbH
Alte Landstrasse 6
Telefon +41 56 500 01 40
Direkt +41 56 500 01 41
E-Mail [EMAIL PROTECTED]
Zope3-dev mailing list