What's the best way to minimize the need of run time checks?

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Aug 10 02:16:44 EDT 2016


Juan Pablo Romero Méndez wrote:

> This is interesting. You are Ok having runtime errors?

You're going to have runtime errors in any case, whether
they come from code you've put there yourself to check
types, or from somewhere deeper down.

The only difference is that checks you make yourself
*might* catch errors slightly sooner, and *might* be able
to provide better diagnostics.

However, experience has shown that, the vast majority of
the time, type errors in Python are caught pretty much
immediately, and the stack trace provides more than
enough information to pin down the source of the problem.
So, putting in manual type checks is hardly ever worth
the effort, and can even be counterproductive, since it
interferes with duck typing.

Occasionally there will be a situation where a type
error results in a corrupted data structure that leads
to problems later. But those cases are relatively rare
and best dealt with as they come up.

-- 
Greg



More information about the Python-list mailing list