[Zope3-dev] interface conventions: default=_RAISE_ERROR

Florent Guillaume fg@nuxeo.com
Wed, 15 May 2002 12:42:18 +0000 (UTC)


> FWIW, I generally feel that getattr() is broken (but obviously can't
> be changed) and that accessors generally shouldn't raise an exception.
> dict.get() is the right and convenient model.  I definitely think that
> the semantics of whether an exception is raised or not should never be
> decided on the basis of an argument.

I am of the opposite opinion. I feel that the simplest method should
always raise an exception in case of error instead if failing
"silently". That's what exceptions are for. Otherwise you get subtle
bugs.

For that reason I like getattr and dislike get.

If I want a function that really returns None or something in case of
error, it's always easy to define a suitable try/except.

The only thing I'm not sure about is the speed: does using an exception
and treating it in the calling function have noticable speed differences
vs. returning "default" ?

(And prefer to see "default" spelt "error_value" or "missing" to better
show the intent.)

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com