Andy McKay

Sep 04, 2007

Generating Archetypes

Go back about 4 years to the first Vancouver Python and Zope Conference. Jim Roepcke, Joel Burton and I are on the beach looking out the mountains. I'm arguing what I really want is to be able to write content types in XML. None of this messing about with Python. Have something that is simple to jump into, easy to maintain and can allow tech savvy users easily get into Plone.

As ever, with great dignity and grace Joel kindly beat me down. What happens when you want to do something not covered in the XML, those custom methods to do processing can't be expressed in Python. My response was something about making CDATA blocks containing Python, not very convincing.

It seems Vidar has done something like this: Congratulations to Vidar for that, it's very cool and I was quite excited by it. Well done.

But I have confess I've still got this nagging problem. It's not XML or Python. It's a whole new syntax. That worries me for a few reasons:

  • Support of the syntax is always up to us.
  • Creating and supporting any tools for it are up to us.
  • It's another barrier to newbies, a new syntax, a new abbr.
  • My brain is full. I can keep Python, SQL, Ruby, PHP (yes don't ask), Javascript, Page Templates and bash in my head, but my brain is mostly mush and I can't keep it all up there.

If you look at the syntax my first thought it looks kinda like Python. Why aren't we doing it in Python? That's mostly because the Python generating a content type sucks. It's long and hard and fraught with syntax errors and boilerplate code. But wait why are we doing code generation at all? Philip hit this point on the head:

Why do we actually have to generate all that code? I mean, it's ok to use paster for creating the absolute bare minimum boiler plate (directories,, etc.). But why is all the rest so verbose? Shouldn't we perhaps reduce all that verbosity? Shouldn't the common case simply be less to type so that we need less tools to get us there?

That .wsl code is not very removed from Python. Is that easier or harder to write than Python? One of the success of things like Django and Rails is that the code is actually pretty simple and hence not all scary to look at. A sample model for Django on that would look like this... first create the project: startproject contactbook
cd contactbook startapp contacts 

Model code is simple:

from django.db import models

class Contact(models.Model):
    homephone = models.PhoneNumberField()
    address = models.TextField()    
    class Admin:

Don't forget to turn on the admin interface in (uncomment one line) and you are done. This isn't a who can write the application in the least lines of code competition, but it is interesting when I look at the power I can get from Django with way less than Archetypes.

I can give up on the XML, it's not the answer to everything. But simple and easy to write Python code allows:

  • Lower barrier to entry, if you are using Plone you need to know Python anyway.
  • We don't have to maintain any tools, parsers etc.
  • One less abbr and tool for new people to worry about.

With simple code, removing the boiler plate you have something that hopefully is easy to get into and easy to use. But once again, congratulations Vidar on a very good development that hopefully gets some traction behind it.