[Zope3-dev] Re: Merging schema & interfaces (was: "Sub interface")

Casey Duncan casey at zope.com
Tue Mar 2 11:44:03 EST 2004


On Tue, 02 Mar 2004 11:39:23 -0500
Jim Fulton <jim at zope.com> wrote:

> Casey Duncan wrote:
[..]
> > 
> >   invariant(lambda thing: thing.expiration_date >
> > thing.publications_date,
> >             'Expiration date must be later than the publication
> >             date')
> 
> So would this raise some sort of exception using the second argument
> if the first arguments returns false?  I think this could work well.
> 
> I too prefer the lambda in a case like this.

I'm not sure it would still use the same invariant function, maybe it
would be a specialized one that auto-raises an error if the invariant
function returns false. I dunno.

> > More complex invariants could be written like Jim's example.
> > Something I find a bit strange about that though is that
> > "cityStateZip" becomes like an instance method defined as a function
> > assigned to the interface. Its a bit funky conceptually, it
> > certainly stretches the notion of what an interface is.
> 
> Agreed. A lambda is much more readable, IMO.

Funny, I never thought I'd find myself agreeing with a statement
containing both "lambda" and "more readable" ;^)

> We'd need to decide on how we'll get exceptions raised in cases like
> this.

Either invariant takes an exception or string as a second argument or
another function is invented for this purpose.

-Casey




More information about the Zope3-dev mailing list