Testing dynamic languages

Emmanuel Surleau emmanuel.surleau at gmail.com
Sat Apr 4 16:17:58 CEST 2009

On Saturday 04 April 2009 15:37:44 grkuntzmd at gmail.com wrote:
> I am a Java developer. There, I said it :-).
> When I am writing code, I can  rely on the compiler to confirm that
> any methods I write will be called with parameters of the "right"
> type. I do not need to test that parameter #1 really is a String
> before I call some method on it that only works on Strings.
> If I am writing in Python, since it is dynamically, but strongly
> typed, I really should check that each parameter is of the expected
> type, or at least can respond to the method I plan on calling ("duck"
> typing). Every call should be wrapped in a try/except statement to
> prevent the method (and program) from crashing when my method is
> called with an integer instead of the expected string.

Well, it depends on what you're trying to do, really. You do *not* want to 
check parameters in every function. If you are designing a library, it is 
strongly advised to document what kind of parameters your functions 
expect. Otherwise, if your program will handle arbitrary input, you should 
check its format and reject it if it's invalid.



More information about the Python-list mailing list