The Samurai Principle
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Sep 12 03:55:01 EDT 2010
On Sun, 12 Sep 2010 12:08:26 +1200, Lawrence D'Oliveiro wrote:
>> And that is exactly the reason why the Samurai Principle says to not
>> return None when the function fails to do what it intended to do.
>
> How can the function “fail” when it returns what it is specified to
> return?
Are you trolling?
On the unlikely event that you're not, if you have a function called
"len", the *intent* of the function is to return the length of its
argument. That's why it's called "len" rather than "raise_exception" or
"return_none", say.
The use of the term "fail" is entirely unexceptional here. It is normal
English to say such things as "the function re.match() returns None if
the regular expression fails to match" or "if we fail to acquire a lock,
raise an Exception".
--
Steven
More information about the Python-list
mailing list