Saturday, May 10, 2003

Generics in CLR v.Next

Don loves to make
a splash. He's a good guy, so I'll help indulge him by encouraging everyone to check
out his blog. He just blogged this
interesting nugget
. It's a short description of the upcoming support for generics
(aka templates) in the CLR. It looks pretty cool. And although I'm a huge fan of staying
away from code that's too clever for its own good (which is why I was never fond of
C++ templates), I have to admit there have been a few times lately when having generics
would have been nice.


  1. dude, you've got the C++ templates all wrong ( :) ): I totally agree with "staying away from code that's too clever for its own good .." but templates are arguably one of the few features in the language that make any true difference. To me, there is something liberating about not knowing what T is; it forces me to focus on one thing that should matters most when writing code: algorithm.


  2. Well, it's great if you can figure it out, but templates in C++ were one of those things like pointers: the few who understood loved them. They were merely a barrier to entry for everyone else. Look where pointers went.

    That may be a terrible analogy, but I maintain that technologies that are hard to understand are less useful. We'll see what happens.

  3. Once you 'get' templates, it is easy to use. The problem is understanding them at first and also figuring out how to use them in your current code. I like to wait a little while to let the bleeding edge technology sink in a little bit before I go adding it to my codebase. When I read don's entry, I understood generics right away because I've grown accustom to the C++ templates.

  4. I agree that generics seem to be fairly intuitive. I would not, however, apply that term to C++ templates.

    I remember being called in on a project one time. The designer had made extensive use of templates. I had a hard time parsing it, so I asked one of the developers, "So, do you understand the code you're working with?" The answer was, "Well, I think the designer does..." I got the same answer from the next two developers I'd asked. I stopped wondering why they were two years overdue.

    These were reasonably smart guys - I just think that the elegance that templates can add is often offset by the cognitive overhead they introduce. Hopefully the generics stuff will be easier to comprehend, because I am a huge proponent of "easy" over "clever".