Why static typed languages are sometimes better.

George Sakkis gsakkis at rutgers.edu
Fri Jul 2 04:09:04 EDT 2004


Now is this a coincidence or what ? Just a few days ago I posted a
very similar typing accident I had. This made me write a simple
runtime type checking module, which would presumably be useful to
prevent such pitfalls. I'm not sure though if it adds up much to the
simple isinstance() assertions. Here's the original post:

http://groups.google.com/groups?hl=el&lr=&ie=UTF-8&threadm=Pine.LNX.4.44.0407010856480.31307-100000%40ccc1.wpi.edu&rnum=1&prev=/groups%3Fq%3Dgroup:comp.lang.python.*%2Bsakkis%2Bgroup:comp.lang.python.*%26hl%3Del%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python.*%26selm%3DPine.LNX.4.44.0407010856480.31307-100000%2540ccc1.wpi.edu%26rnum%3D1


> I just had an interesting little surprise.  I've got a method that takes 
> a string as an argument.  I wanted to change it to take either a string 
> or a tuple of strings, so I did my usual "test first" thing.
> 
> I changed the unit test I already had from calling it with a string to 
> calling it with tuple of two strings.  I then ran the test, expecting it 
> to fail.  The next step would be to go write the code to make the test 
> pass.
> 
> Amazingly, the test passed (that means I'm done, right?).  Well, it took 
> me a moment to realize that the only thing I ever do with the argument 
> in the current version is use it as a dictionary key.  Since a tuple of 
> two strings is a valid key, so the test passed just fine.  Sometimes the 
> language is just too forgiving :-)



More information about the Python-list mailing list