[Zope3-dev] Re: ZCML

Shane Hathaway shane at zope.com
Tue Aug 26 16:28:35 EDT 2003


Chris Withers wrote:
> Stephan Richter wrote:
> 
>> This would totally bloat ZCML and make it unworkable. I mean theory is 
>> nice, but Zope is a software, so we have to look at the practical side 
>> of things. If ZCML fulfills all XML semantics but is unusable, we lost 
>> everything we tried to accomplish.
> 
> 
> I'm still not really convinced by the whole XML thing anyway.
> 
> Surely a class structure would be just as convenient a way of building 
> up this kind of information, with subclassing being used for overriding 
> and reconfiguring on the fly?

Before writing an XML schema for configuring Ape, I made my best effort 
at doing just that.  I wanted to prove for myself that either Python is 
the right choice or it's inadequate for the task.  You can see what I tried:

http://cvs.zope.org/Products/Ape/lib/apelib/zope2/Attic/baseconf.py?rev=1.1.2.2&content-type=text/vnd.viewcvs-markup

The first thing that's wrong with this is the many ordering 
dependencies.  If I wanted to copy a piece of the configuration and 
modify it in my own product, I'd have to be very careful to get the 
right things declared or imported before I can make my own declarations. 
  Programmers don't mind this step, but others do.

Second, subclassing was not expressive enough.  When you subclass, you 
inherit a flat namespace of attributes.  What I actually wanted was to 
inherit one level deep: a dictionary attribute should extend, not 
replace, the contents of an inherited dictionary attribute.  But I think 
that would surprise people a lot.  I felt like I was straying from 
Python ideals.

Third, it occurred to me that since overriding is done by extending, I 
could provide no sane way for people to override declarations made by 
base classes!  I realized that in this code, even the choice of base 
class must be configurable.  This strays far from Python standards.

I realized that Python, although it has a nice, reusable syntax, also 
comes with a large bag of semantics carefully tuned for programming and 
scripting tasks.  In contrast, XML gives you the freedom of inventing 
whatever semantics you want while reusing a common syntax.  ZCML needs 
this flexibility, therefore, ZCML is better written as XML than as Python.

That said, I also came up with a near-Pythonic syntax for this stuff. 
Right now, I have something like this:

<mapper name="foo" parent="bar">
   <serializer name="baz" factory="zope.baz.factory" />
   <gateway name="baz" factory="zope.xyz.factory" />
</mapper>

It might be nice to write that like this:

mapper(name="foo", parent="bar"):
     serializer(name="baz", factory="zope.baz.factory")
     gateway(name="baz", factory="zope.xyz.factory")

However, I didn't think that was different enough from XML to justify 
the extra work.  I'd have to document it.  Someone else has probably 
already done it, too.  (If not, someone should. ;-) )

Shane




More information about the Zope3-dev mailing list