Q&A with VJ# and C# Team on Generics

From a conversation with Brian Keller, the PM on the VJ# team and some additional input from C# dudes, Dan Fernandez and Eric Gunnerson .

For further enlightenment, read Jason Clark’s introductory article on “what is generics…“ from Sept 2003 MSDN Magazine.

Q) I know I can’t code VJ# for beans, but why can’t I create generic classes in VJ# like I can in C# and VB.NET?

A) VJ# can consume generics but cannot create generics.

Q) But Generics is part of the CLR. Why is it acting like it is only a language enhancement for C#, VB.NET and C++.NET?

A) Generics is baked into the CLR as much as other data types are built into the CLR and IL. The way generics are implemented is that when you use a generic type, a “placeholder” is added where the generic value will be used in the resulting IL.  Only on first execution is a specific version of the specialized class created.  Once you get to the IL level, there is nothing language specific going on, it’s all the CLR.  The BCL has several examples of generics including collection classes available in the System.Collections.Generic namespace and ObjectSpaces, an object-relational mapping tool is using generics for their underlying data structures. Generics are present at the IL level – that is, if you declare a parameter as a List<int>, you will get that type if you use reflection on the parameter.

Q) So if it is in the CLR and I can’t fully use it in VJ#, does that mean it is up to the language developers to leverage it (or not)

A) Correct, generics were not added to the Common Language Specification because it puts a large onus on language developers that would then need to implement generic data types in their compilers. It will likely be added to the CLS in the Orcas timeframe (following Whidbey).

Q) Aha! This is definitely a point of confusion/contention because at first many people kept saying that generics is a C# language enhancement and suggesting that it did not exist in VB.NET, which pissed off a lot of VB people. Even Elden Nelson wrote something that was interpreted that way in an editorial for ASPNetPro. Then the word was “no no no – generics is part of the framework and therefore available everywhere…” But that statement doesn’t quite work as we see with the lack of the implementation in VJ#. So what we are really seeing is variations on implementation: C# does it one way, VB.NET does it another and VJ# does it another. The lack of the “consuming“ implementation in VJ# is not really any different than the language difference, for example, between how we declare a variable in VB.NET and how we do that declaration in C#.

A) You are correct, C#, Visual Basic, and C++ will support creating and consuming generics.  J# will only support consuming generics at this time, largely because the Java community has yet to start using generics.

Q) Let’s qualify “Consume generics” for our audience: does that mean if I have an assembly that I wrote in VB or C# and it contains some generic custom classes, then I can use those from a VJ# assembly just as I would access the system.collections.generic classes?

A) Correct, you can use these classes, you simply cannot create your own.

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.