[Zope3-Users] Re: ZCML, practicality, purity (was "Excellent perspective...")

Shane Hathaway shane at hathawaymix.org
Thu Dec 22 11:47:35 EST 2005


[Shane]
>>Are you sure ZCML is The Right Way?  I know its purpose (since I helped
>>invent Zope 3): to combine configurations by multiple developers without
>>imposing a particular workflow.  However, I maintain that Python code could
>>do the job better.  The Python code I have in mind is not the same as
>>Jeffrey's examples.  I'll elaborate if there's interest.

[Pete Taylor]
 > *ping* for interest in elaboration on the code you have in mind...

Ok.  Here are two snippets that express the same thing.  First in ZCML:

   <browser:skin
       name="Rotterdam"
       interface="zope.app.rotterdam.Rotterdam" />

   <browser:resource
       name="zope3.css"
       file="zope3.css"
       layer="zope.app.rotterdam.rotterdam" />

Now in Python (hypothetical):

     from zope.app import rotterdam

     def configure(context):
         context.browser.skin(
             name='Rotterdam',
             interface=rotterdam.Rotterdam)
         context.browser.resource(
             name='zope3.css',
             file='zope3.css',
             layer=rotterdam.rotterdam)

All functionality and capabilities of ZCML are retained, but there are 
important, subtle differences.

- I could conceivably type configuration directives at the interactive 
Python prompt.  I could use the standard dir() and help() functions to 
find out what directives exist and how to use them.

- If I want to register a lot of similar things, in ZCML I have to 
either repeat myself, leading to poor maintainability, or create new 
directives, leading to directive proliferation.  In Python I can use 
variables, loops, functions, etc., reusing skills I already know.

- If I want to debug a registration, I can use pdb or any other Python 
debugging tool.

- Code snippets can include both the code and the default configuration 
(yet users are not forced to use the configuration), making code samples 
clearer.

Those are the technical arguments.  There is also the marketing argument 
that a lot of the target audience has been burned by XML, but I don't 
think that's the right basis for making a decision.  I sincerely believe 
Python code would be better than XML for the technical reasons I listed 
above.

Shane


More information about the Zope3-users mailing list