The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Steven D'Aprano steve at pearwood.info
Tue Mar 22 21:14:39 EDT 2016


On Wed, 23 Mar 2016 01:02 am, BartC wrote:

> And, forgetting file input for a minute, what about function return
> values in general; should they still be allowed to return some status or
> error codes, or does it all have to be exceptions now?

It doesn't *have to* be exceptions, but exceptions are considered to be a
generally better approach. Some people disagree, must famously Rob Pike,
the highly respected creator of Go (the language, not the ancient Chinese
board game). But Go's approach of returning error codes is most certainly
not Pythonic. (It might be Go-thonic :-)


> I mean, is a function allowed to still return True or False, or just
> False? (Or perhaps just nothing if the exception mechanism can signal
> either.)


You can answer this question yourself by looking at what functions are
provided in the standard library and built-ins:

py> "hello world".find("goodbye")
-1
py> "hello world".startswith("goodbye")
False



-- 
Steven




More information about the Python-list mailing list