The Samurai Principle

Ian Kelly ian.g.kelly at gmail.com
Wed Sep 8 08:57:52 CEST 2010


On Tue, Sep 7, 2010 at 9:38 PM, Phlip <phlip2005 at gmail.com> wrote:
> Everyone gets defensive about the design flaws in their own language.
> But the django.db situation is not even a design flaw; just a
> misinterpretation of the Samurai Principle. int('yo') shall throw an
> exception, but a missing record could be the result you were looking
> for, so it's not exceptional.

I consider it exceptional because it breaks the rule that
Model.objects.get(...) returns an instance of Model.  If it can also
return None, then this needs to be checked for every time the method
is called, because None does not implement the Model interface and
will break if you try to use it like that.  You're still doing
exception handling; you're just doing it with an if instead of a
try-except.  I prefer to do exception handling in a block clearly
marked as an exception handler.

Out of curiosity, would you also regard the case where two matching
records are found instead of one as not exceptional?  After all, it
could be the result you were looking for.  What should QuerySet.get
return in that case, if it doesn't raise an exception?



More information about the Python-list mailing list