From Twitter yesterday, I was griping about how once you use a Generics Constraint once and suddenly that same constraint has to immediately ripple through the call stack. Scott Allen posed me a stumper of a question:
What’s worse: generic constraints, or checked exceptions [in java]?
Oh wow, that’s a nasty choice. Can I have neither? I’d call both things Noise Code. Smelly, useless, noise code.
- Generics Constraints: 90% of the time it’s just to make the compiler shut up and let my code work. Dear C# team, could you deemphasize all the COM interop work in C# and making C# do kloogey dynamic typing, and GIVE ME FAR BETTER TYPE INFERENCE ON GENERICS SO I CAN GET SOMETHING DONE (contra/covariance makes your little academic hearts go pitter patter, but that won’t really help me much)!!!!! Anyway, ReSharper can mostly figure out how to propogate the generic constraints, but it gets confused easily and sometimes the constraints will conflict and… Human intervention is usually necessary. Andy Sherwood calls this “the where tentacles.” Nice.
- Checked Exceptions. Much more pervasive, but IntelliJ can handle adding the “throws blah” stuff without any trouble. The problem is that checked exceptions are so much more common and pervasive. Needless to say, I don’t find checked exceptions to be the slightest bit useful.
I guess I’d rather live with the generics constraints than waste time with checked exceptions. Now, keep checked exceptions out of the language, give me F#/OCaml style type inference instead of a nanny compiler (are you sure it’s okay for this object to do this? Confirm or deny), and make ALL methods and properties virtual by default, and I’m a happy camper. If I want dynamic typing, I’ll use IronRuby. If I need office integration, I’ll get a contracter to write VB.Net.