[Zope3-dev] interface conventions: default=_RAISE_ERROR

Jim Fulton jim@zope.com
Thu, 23 May 2002 08:49:24 -0400


Gary Poster wrote:
> 
> On Wednesday 15 May 2002 03:05 pm, Leonardo Rochael Almeida wrote:
> > On Wed, 2002-05-15 at 15:13, Jim Fulton wrote:
> > > I think we're on the right track looking for method pairs.
> 
> <snip>
> 
> > Another suggestion, make the getXXX raise the error and create a
> > lookupXXX (or lookUp) that takes a default. The reasoning is that when
> > you ask zope to get something, you expect that it does so and if it
> > doesn't then this is an error and should raise an exception, whereas if
> > you ask zope to look something up and it doesn't find it, well, you get
> > the default.
> 
> RDM suggested "query" in the same vein, but not seriously.  I think "find"
> has some small merit, since (1) it's short, (2) you could use similarly
> debatable logic to your "lookup" idea to endorse "find", and (3) the find
> method in the string sense does return a default now when nothing is
> available (-1, in its case).
> 
> so to clarify
> 
> getXXX(YYY)
> findXXX(YYY, default=None)
> 
> I like it, but maybe I'm easy to please.

Thinking about it some more, I like query better because it implied that
there's a question about what will be retured. In fact, at this point, 
I like query a lot and can't think of anything better. :)

I suggest the following accessor style, which I'll write up in a 
separate proposal:

  getXXX(parm1, ..., parmn)

     Get an XXX. If XXX is not found, raise an error.

  queryXXX(parm1, ..., parmn, default=None)

     Get an XXX is there is one, otherwise return the default, which
     defaults to None.

Jim

--
Jim Fulton           mailto:jim@zope.com       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org