Ian Bicking: the old part of his blog

Re: More on Python Metaprogramming

I think one of the key differences the snakes&rubies brought out was David's (and by extension, Ruby's) love of DomainSpecificLanguages. Which seems to be a hot item these days, and as David says in the post you linked to about the event, not a focus of as much interest or support in Python.

And part of the reason for that is highlighted in the Magic & Backtracking post: backtracking and clear indication of where something came from (via namespaces etc). I'm not saying Ruby doesn't do this nicely (I have no idea), but DSLs of the ruby-style in python seem to require metaprogramming monkeying, which immediately feels "unpythonic". But I'm not convinced that the ActiveRecord DSL is the only sane one for representing Database models.

Say we rename "ForeignKey->Is_A", "OneToMany->Are_Many" "ManyToMany->Is_Many_And_Are_Many", ignoring the awkward is_a inheritance meaning. Now, in the case where we actually have to specify the class that a column maps to:

Only slightly tortured English:

A Project belongs to a project manager who is a Person.
A Project's projectManager is a Person

A Project has many Milestones which are (of) Milestone.
A Project's milestones are many (of) Milestone.

(I personally think ManyToMany breaks down in both cases, because in both cases we are really specifying the attribute for this class to access via: I would rather specify just "Many" on both sides.):

A Project has many and belongs to many categories which are (of) Category
A Project's categories are many (of) Category (and by the way, a Category's projects are many (of) Project

Rails: Project belongs_to a projectManager (class Person)
SQLObject: Project projectManager IsA Person

Rails: Project has_many milestones (class Milestone).
SQLObject:  Project milestones Are_Many Milestone

... (getting off track, leaving it in here to show my train of thought)

At which point Rails people will scream DRY, and I'll probably agree, so allow the class to be derived from the name.

Ok, so basically I'm saying with python we're stuck with parentheses and attributes. And because of attributes, we're somewhat stuck with = being our verb. But that just means our language for models is different:

class Project(SQLObject):
 projectManager = A(Person)
 milestones = Many()  # explicitly: Many(Milestone)
 categories = ManyAndMany() # again, from the Project side I'd ideally like if this was just Many()

(ie, to some extent we're getting pulled into a debate constrained by ActiveRecord's words in their DSL for models.)

Comment on More on Python Metaprogramming
by Luke Opperman