You should not provide type security in this way. Yes, someone can intentionally break your code by providing values โโfor which your container will not work, but this is the same with other languages. And even if someone put the correct value for the parameter in a method or member function, it does not necessarily mean that it is not broken: if the program expects an IP address, but you pass the host name, it still will not work, although both can be strings.
I say: Python mentality is fundamentally different. The duck picks up basically: โHey, I'm not limited to certain types, but the interface or behavior of the objects. If the object really acts like the object that I expect, I don't care - just go for it.
If you try to introduce type checking, you basically limit one of the most useful features of the language.
Speaking of which, you really need to pass testing based on testing, or at least single testing. In fact, there is no excuse not to do this with dynamic languages โโ- it simply moves errors (of the type) that are detected at another stage of the build process, away from compilation time to running the test suite several times a day. Although this seems like an added effort, it will actually reduce the time spent debugging and fixing the code, since it is inherently a more powerful way to detect errors in your code.
But thatโs enough, Iโm already incoherent.
Jim Brissom Sep 20 '10 at 8:50 2010-09-20 08:50
source share