[Zope3-dev] interface conventions: default=_RAISE_ERROR

Gary Poster garyposter@earthlink.net
Wed, 15 May 2002 15:13:34 -0400


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.

> In either case, I think that the default argument should be optional
> defaulting to None. This mimics the dictionary behaviour about defaults
> and I believe this is what most people will use the default argument for
> anyway.

As shown in my example above, I agree.

Gary