Typing Done Right

I\’m a big fan of all the sort of agile/dynamic sort of stuff. C2:TestDrivenDevelopment, C2:IterativeDevelopment, etc. But one thing I\’ve always had trouble with is accepting C2:DynamicTyping as the Right Thing. I mean, yeah, C2:ManifestTyping sucks, but C2:TypeInference is there to pick up the slack, as ML and Haskell show. With type inference, you get the clear code of dynamic typing, with the safety and performance of static typing. Which, I thought, was everything.

Yeah, I had heard the whining of those die-hard dynamicists who procliamed that there are correct programs that can not be statically typed. I didn\’t disagree, but I felt that for all practical purposes it was irrelevant. However, I\’m now working on a project where static typing gets in my way every day. It\’s unbearable.

I have a solution, which I think balances all the important bits. Yes, it\’s not perfectly \”safe\” like you static guys like, but it gives you the flexibility when you need it.

  1. type inference is key;
  2. there should be something like C2:CommonLisp\’s DECLAIM that allows you to say whether un-inferenceable bindings are errors, warnings, or ignored (and should default to errors, making the static guys happy);
  3. you can DECLARE individual bindings as dynamic, regardless of whether they\’re treated as errors.

Anyone who just wants dynamic fun DECLAIMs that un-inferenceable bindings are ignored, while others can make them warnings or errors and deal with the exceptions on a case-by-case basis. Type inference is always used whereever it is possible.

Comments are closed.