[Zope3-dev] Re: views/foo versus context/@@foo

Jim Fulton jim at zope.com
Fri Jun 25 10:05:32 EDT 2004


Martijn Faassen wrote:
> Philipp von Weitershausen wrote:
> [snip]
> 
>> I'm actually surprised that this works and to be honest, I'm not too 
>> happy about it.
>>
>> The 'views' namespace is somewhat magic in a way that you don't know 
>> for what view is gotten? For context? For zope.interface.Interface? 
>> You wouldn't know. 
> 
> 
> I do not understand how this is magic. It's for getting another view for 
> the same context, right? I mean, 'views' would be standing in for all 
> the views for the current context object.

It's not magic. It's just isn't necessary and violates the "one way to
do it" principle.

> 
>> That's why the context/@@foo notation is always preferable because it 
>> makes it quite clear for what object you get the view.
> 
> 
> Well, since I don't see views as magic as it could mean exactly the 
> same, that one isn't really an overwhelming argument to me.

The things is that /@@foo can be used with other objects too.
It's more powerful. I added views as a stopgap until we
could use @@ in zpt path expressions.


>> So, I think we should once and for all deprecate 'views' (not just in 
>> our telling people, but in the code!) and hunt down the places where 
>> the '@@' is left out. Furthermore, we should make the context/foo 
>> magic disappear (or at least generate deprecation warnings), so that 
>> in the future, only context/@@foo is possible for views.
> 
> 
> The context/foo magic is rather inherent to the way Zope 3 works, isn't 
> it? Isn't this due to the way the publisher machinery works in Zope 3?
> After all I can say: object/foo in a url. There's even a whole line of 
> argument pointing this out to stop people like me worrying about 
> exposing poor innocent users to urls with @@weird++characters@@in++there.

Right. Note that traversal rules are governed by adapters.  Different
objects can have different rules.

> We can of course argue that this default is wrong and that people should 
> always be typing /@@foo when they want a view.

That would be wrong for urls.

It would ne nice in zpt.  We currently don't have a way to have separate
rules for urls and zpt paths,

 > Simpler way would be to
> make 'views' the default way to get a view in ZPT.

No.

> The way as it currently works invites "it works if I forget to do 
> something right, until suddenly it doesn't" bugs.

In zpt paths, you should always use @@ if you want a view.

If you don't case about the appearence of @@ and don't want to think
hard, then you should use @@ in urls too. Many people hate @@ and
are willing to think hard and risk namespace conflicts to avoid it.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-dev mailing list