Linked by Amjith Ramanujam on Tue 5th Aug 2008 16:48 UTC
Thread beginning with comment 325834
To view parent comment, click here.
To read all comments associated with this story, please click here.
To view parent comment, click here.
To read all comments associated with this story, please click here.





Member since:
2005-12-22
This a good example, of how you in python sometimes need to compensate the lack of explicit typing by adding more tests for the sake of rubustness of the code.
That is true. You would have to create some additional logic for keeping the types explicitly "clean" if that is necessary. But is it really necessary that often?
For example, with numeric types, is it ever necessary to limit a list of objects to be of type double? With duck typing, everything that looks like a number, works like a number.
Or another common example is file-like objects in Python. If you create functions which for example count all the lines from a file: the input doesn't need to be a file, as long as it implements the methods that the line counter uses; thus implementing itself as a file-like object. And the rest falls to the exception handling system.
For before-runtime checking, there is for example PyLint.
What I'm arguing: is static typing really so much better, that you wouldn't want to use the power of dynamic typing?