[Zope-dev] implementing zope.component 4.0

Gary Poster gary.poster at gmail.com
Mon Nov 30 12:34:52 EST 2009


On Nov 30, 2009, at 11:51 AM, Chris McDonough wrote:

> Tres Seaver wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> 
>> Gary Poster wrote:
>>> On Nov 27, 2009, at 6:32 AM, Martijn Faassen wrote:
>> 
>>>> Utility lookups versus adapter lookups
>>>> --------------------------------------
>>>> 
>>>> There was some discussion on whether utility lookups are really 
>>>> something fundamentally different than adaptation as adaptation 
>>>> *creates* a new instance while utility lookup uses a registered 
>>>> instance. I think the essential part here is however: "give me an 
>>>> instance that implements IFoo", and utility lookup fits there. We could 
>>>> even envision a way to create utilities that *does* instantiate them on 
>>>> the fly - it shouldn't affect the semantics for the user of the utility.
>>> As above, I disagree.
>> 
>> The root of the disagreement here is that you seem to want the *caller*
>> to care about something which is important only to the person who
>> *registers* the thing being looked up.  From the caller's perspective,
>> the call site needs an object implementing IFoo, looked up using some
>> number N of context arguments, where N could be 0 (no context required
>> to find the object).  The fact that, under the hood, an adapter lookup
>> happens to call a factory, passing the context args, is not relevant *to
>> the caller*.
> 
> I understand that the idea explained above is conceptually integral to a lot of 
> people, and basically unquestionable.  But as devil's advocate sort of thing 
> can we put this traditional worldview aside for a minute,  and just sort of 
> take this from ground zero?
> 
> In "normal Python", callers often do need to understand whether the function 
> they're calling is a factory which constructs a new object, or a function which 
> returns a "global", because the caller needs to know what the impact of 
> mutating the result is.
> 
> We call non-factories utilities and we call factories adapters.  So the caller 
> *already* needs to make a distinction between the two.

Yes.

Gary


More information about the Zope-Dev mailing list