Zope 3.0, and why I won't use it

Josiah Carlson jcarlson at uci.edu
Wed Nov 17 02:50:43 CET 2004


Ian Bicking <ianb at colorstudy.com> wrote:
> 
> Josiah Carlson wrote:
> >>Since the actual need for type-checking is extremely rare, I contend it
> >>should not _at all_ be a candidate for a syntax to facilitate it.  Since
> >>the actual need for adaptation is much wider, I contend it's the one
> >>obvious choice for the "nice syntax" if any.
> > 
> > 
> > Sounds reasonable, but there will be a group of people who will beg and
> > plead for type checking, because they want "static type checking on
> > function call and return".
> 
> Yes, but they've been begging for it for years.  They seem insistant 
> that this Python Thing will never catch on without these important features.

And they can keep insisting.  It hasn't stopped it from catching on yet
*wink*.


> Anyway, a much more general and useful feature would be contracts. 
> Which is just to say, a formal place to put constraints on input and 
> output for a function.  Contracts could include type checking -- 
> sometimes quite validly -- but not necessarily.  There's no type that 
> can indicate "only valid username strings" or "only integers contrained 
> by some global variable".

Certainly not, but an arbitrary 'argument validator' decorator is just
minutes away from someone implementing it (and likely has more than a
few times already).


> > @ multi_dispatch_to_methods
> > class A(object):
> >   dispatch = dispatch_factory()
> >   
> >   @ dispatch(int)
> >   def foo(x): ...
> > 
> >   @ dispatch(float)
> >   def foo(x): ...
> > 
> > 
> > It may have a couple warts, but it is implementable today.
> 
> Phillip Eby just did this, in like the last week.  It's very cool:
> 
>    http://peak.telecommunity.com/DevCenter/VisitorRevisited
>    http://www.eby-sarna.com/pipermail/peak/2004-November/001916.html
> 
> It looks similar to what you were thinking:
> 
> class A(object):
>      @dispatch.on('x')
>      def foo(x):
>          """This is a dummy function, for documentation purposes"""
> 
>      @foo.when(int)
>      def foo(x): ...
> 
>      @foo.when(float)
>      def foo(x): ...
> 
> Of course, you can use interfaces in addition to types, and you can also 
> use arbitrary expressions (e.g., @foo.when("x % 2") and @foo.when("not x 
> % 2") to dispatch odd and even numbers separately).

There goes Phillip Eby going off and doing something reasonable again.

 - Josiah




More information about the Python-list mailing list