[Zope3-dev] Allowing views to be registered for classes ratherthan interfaces.

Martijn Faassen faassen@vet.uu.nl
Sat, 19 Jul 2003 10:37:03 +0200


Garrett Smith wrote:
> Martijn Faassen wrote:
> > Of course this is a good argument for views directly on classes, as:
> > 
> > class Foo:
> >    def hello(self):
> >        return "Hello world!"
> > 
> > is even less stuff to explain.
> 
> +1
> 
> Now when a developer get hooked on how easy it is *not* to write and
> maintain an interface, what are the incentives for getting him/her to
> move toward IFoo?

Good question. 

A first step would be:

   * create IFoo for documentation; view still depends on the class

This is a rather sensible step to take. It's the canonical thing to
do for documentation in Zope 3. Especially if other client code is
expected it makes sense to document. Probably the following step can then
also be encouraged, as introspection/documentation generators will
pick this up:

   * make Foo say it implements IFoo

I'm not sure how easy it is then to convince the developer to move along to
this step:

   * Make the view depend on IFoo, not on Foo directly.

Is it a disaster if this doesn't happen? This depends on the codebase.
If Foo gets multiple client code bases using it, there'll be pressure
to switch over to IFoo. Of course the client code can already do so,
it's only the one view that doesn't, so this might still not convince
the developer as things still work. People with client code don't have
much reason to complain either.    

If IFoo now gets another implementation, it will become very clear to
switch over to depend on IFoo with the view.

So, I hope that IFoo will come into independent existence due to 
a normal evolutionary process.

> >> Were I teaching someone Zope 3 development, I'd
> >> start out with a big disclaimer: "don't be lured into thinking this
> >> is a no-brainer just because you're using Python".
> ...
> 
> > But besides this, lots of the people that will come into Zope 3 will
> > not be Python programmers in the first place. They will hardly be
> > programmers. If you have to explain interfaces and unit testing to
> > them before they see "Hello world" when they start out with Python,
> > then this is bad.
> 
> Well said :-)
> 
> But I'd still prepare *my* pupils for the hard road ahead ;-)

Yes, it is good to prepare your pupils and say something about 
interfaces and unit testing, so they know what to look for when they
need it. But it shouldn't be a required skill to get your feet wet
in Zope 3 Python programming, preferably. (I think a case can
be made for minimal knowledge of interfaces to be important, but
unit testing is definitely a step too far to require)

Regards,

Martijn