[ZODB-Dev] RFC: Attributes and Options for IndexedCatalog

Christian Reis kiko@async.com.br
Fri, 31 Jan 2003 00:34:56 -0200


On Tue, Jan 28, 2003 at 03:29:18PM -0500, Greg Ward wrote:
> I think type information about instance attributes should be squeezed
> into a fixed, limited number of class attributes, rather than one
> type-specifying class attr per instance attr.  Therefore ...
> 
> >         class Host(IndexedObject):
> >             _ic_fields = [ attr('name', StringType, unique=1),
> >                            attr('address', StringType, unique=1),
> >                            attr('arch', StringType),
> >                            attr('mhz', IntType),
> >                            attr('os', OpSys),
> >                            attr('daemons', HostDaemonCollection, weak=1) ]
> 
> ... I prefer this approach.

We've gone with this, though allowing people to still specify types in
the old way to be backwards-compatible to some extent. We've used
_ic_options to make it a bit less "field"-ish (nobody calls anything
fields around here). It's checked in to CVS, and we implemented
lazy_numbers for it too (converts ints to floats and vice-versa) so lazy
people don't complain about that *feature* anymore. 

> >         class Host:
> >             name = StringType
> >             address = TupleType
> >             arch = StringType
> >             mhz = IntType
> >             os = OpSys # a class
> >             daemons = HostDaemonCollection
> >             _ic_options = [opt('name', unique=1),
> >                            opt('address', unique=1),
> >                            opt('daemons', weak=1)]
> 
> Yuck.  Not only does this require O(N) class attributes to specify the
> schema (rather than the preferred O(1)), you have to specify the set of
> attributes twice: once as class attributes, and then again as elements
> of _ic_options.  -1 (if I get a vote).

You make a good point here, and yes, it was redundant. This is allowed
for backwards-compatibility (and IMHO a bit more readability ;) but the
new option mechanism allows for a lot of features I'm sure people will
want (default values, etc).

> >     Johan says something about "generating domain class code from XML"
> >     next to me and I feel worried.
> 
> "Git a rope, boys".  >grin<

I'll tie him up with it if he mentions it again. Thanks for the nice
comment.

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL