What’s wrong with the CLS not supporting generics fully?

I saw Brad’s post entitled The Love Affair is Over which is a response to the announcement of support for generics being added to the CLS 2.0 and wanted to chime in. In Brad’s post he mentions that James Robertson shares the same opinion. It seems to me that James has confused CLS (Common Language Specification) and CLR (Common Langauge Runtime), a common misconception, but I’m just not sure if Brad is doing the same or if he just doesn’t like the fact that the proposed CLS rules regarding generics are so weak.

What’s the big deal with the CLS not supporting 100% of the features of generics that are available in the CLR? This only becomes an issue for languages who don’t (yet) have a full knowledge of generics. If you’re not even trying to interop with them (i.e. writing in C# and VB.NET only), then who really cares? As an example today, the unsigned types are not CLS compliant. Yes it sucked that stuff like FileInfo::Length, which can obviously never be negative, has to be a long instead of ulong, but hey we somehow managed to get by. Now consider that generics are far more complex than that and I think it’s fair to not force 100% support for them into the CLS.

As I said in my comment to James’ post:

… granted it would be great to say “all languages built on CLR 2.0 must support all features of generics!”, but… one step at a time. The fact that they even came out with any kind of CLS spec around generics should be considered a win.

So who does this really affect? Two groups of people of people as far as I can tell: a) the language implementers who do not want to support all features of the CLR, but want to play somewhat nice with the other kids in the sandbox and b) the people who choose to use those languages. Surely that’s the minority of people developing .NET applications. The solution for those of us using full featured langauges then? Simply don’t mark your assemblies with the CLSCompliantAttribute.

0 thoughts on “What’s wrong with the CLS not supporting generics fully?

  1. My problem with .NET generics is they’re neutered. They’re not capable of anything significant, save for type safe containers (for which code generation was a very apt solution already).

    Even C++ templates, which most regard as “hackish”, got the latent typing thing correct.

  2. Brad, any chance of describing further what you mean by neutered?

    You offer up C++ templates as a comparison, but surely you must be aware that they and generics are intended for entirely different purposes. Templates are targeted for generative meta-programming, while generics are simply a means of parametric polymorphism (arguably a subset of the former). If they were intended to solve the first problem, yes, they fail to do so. But that’s not the case.

Leave a Reply