[Baypiggies] Type checking - argument for it being bad practice?
jimmy at retzlaff.com
Fri Oct 8 08:39:45 CEST 2010
On Thu, Oct 7, 2010 at 9:22 PM, Seth Friedman <sfseth at gmail.com> wrote:
> I mean, what's wrong with code asserting that what it got passed was what
> was expected? If there's blind faith that stuff will just work beneath the
> scenes, ok, but when i *know* it won't, why not fail there, and explicitly?
> If I write a function that can be called from python code or command line,
> I might get a string of a number or an int, and I will probably forget 6
> months from now what I wrote the code to handle, without some kind of
> prompt. The closer that prompt is to the disconnect, the better.
The other side of this is that your function might work perfectly well
with types you never anticipated. For example you might take an open
file as a parameter. If all you do is call read() on that file, and
don't do any type checking, then later you can also pass in a StringIO
object or an HTTP response object or anything that supports the same
read() call. Type assertions would limit this flexibility.
More information about the Baypiggies