Is this a good idea or a waste of time?

asincero asincero at gmail.com
Thu Aug 24 15:56:42 EDT 2006


Would it be considered good form to begin every method or function with
a bunch of asserts checking to see if the parameters are of the correct
type (in addition to seeing if they meet other kinds of precondition
constraints)?  Like:

    def foo(a, b, c, d):
       assert type(a) == str
       assert type(b) == str
       assert type(c) == int
       assert type(d) == bool
       # rest of function follows

This is something I miss from working with more stricter languages like
C++, where the compiler will tell you if a parameter is the wrong type.
 If anything, I think it goes a long way towards the code being more
self documenting.  Or is this a waste of time and not really "the
Python way"?

-- Arcadio




More information about the Python-list mailing list