Compiler is not substitute for brain, sorry...
Compiler is not substitute for brain, sorry...
Posted Jul 19, 2009 6:32 UTC (Sun) by khim (subscriber, #9252)In reply to: Hmm... May be I misunderstood something by bockman
Parent article: Unladen Swallow 2009Q2 released
Sure, compiler checks are useful. But are not enough, and this is a point that sometime is forgotten in comparing static and dynamic typing.
Sorry, but this is bull-shit.
An API can mantain its formal interface but change its meaning (e.g. the parameter 'length' was inches and now is centimeters ) and no compiler will help you with that.
Fire the person who commited such a change (or revoke his commit rights) - problem solved. It's resposibility of programmer to guarantee that formal interface changes if the semantic changes: new method should get some suffix prefix so it's impossible to mix old and new version, it's not a rocket science. Bad programmer can write awful unmaintable program in any language.
And I don't think that in a dynamic language one has to do explicit unit test for wrong parameter types : misusage of a function is bound to trigger some exception or make anyway fail the test.
Not at all. Take your own example: suppose you have an interface where you enter paraments of sattelite and it returns some stats. Suppose you have two implementations (different approximation methods or something). Unittest for interface will test that everything works for trivial case, unitests for implementations will check error margins and other such things. The exception will be triggered, alright: when orbiter will either try to orbit Mars below surface or "NoSuchMethod" exception will be thrown and the system will be shut down. By that time it's kinda too late...
What you have to do is ensure full code coverage, which is a good practice also in statically-typed languages.
Full code coverage is nice and all, but unfortunatelly it's not an option for a big system: you can only test one component a time, because the whole system is too big.
