[Zope3-dev] interface conventions: default=_RAISE_ERROR

Leonardo Rochael Almeida leo@hiper.com.br
15 May 2002 16:05:39 -0300


On Wed, 2002-05-15 at 15:13, Jim Fulton wrote:
> 
> I think we're on the right track looking for method pairs.
> 
> 
> Maybe the default and no-default cases should be distinguished by
> the starting verb.  I think getXXX should be like dictionary get, 
> except that we should require a default value argument.
> 
> I'm not sure verb to use for the no default case.
> 
> Anybody got any ideas?
> 
> Maybe the no default case should ommit the verb, as in:
> 
>   getRequestDefaultViewName(object, request, default=None)
> 
>   requestDefaultViewName(object, request)

this looks like request is the verb... blame the English language that
has verbs in the imperative looking like nouns most of the time, we
don't have that problem in Portuguese :-) It does make sense, however in
light of the Python dict pattern, where a .get() accepts a default
(defaulting to None) but never raises an error.

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.

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.

	Cheers, Leo

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.