Watch Out For the Generics Explosion

By now, every developer and his mother knows that VS.NET 2005 and SQL Server 2005 has been released. Prepare for the generics explosion as legions of .NET developers retrofit code, happily slapping <T> wherever it fits.

I predict the number of angle brackets in C# will initially increase by 250% only to settle over time to around 75% above current numbers. If you don’t count the angle brackets in C# comments, could be even higher.

But before you go too hog wild with generics, do consider that generics have an overhead associated with them, especially generics involving a value type. Their benefits do not come completely free.

As Rico Mariani pointed out in his PDC talk, generics involve a form of code generation by the run-time. His rule of thumb was that when your collection contains around 50 500 or so items, you’ll the benefits outweigh the overhead. But as always, measure measure measure.

In general, the strong typing and improved code productivity outweigh any performance concerns I have with small collections.

UPDATE: Whoops, I mistyped the number of items Rico mentioned. He said 500, not 50. Thanks for the correction Rico.

What others have said

Requesting Gravatar... wife Oct 28, 2005 7:57 AM
# re: Watch Out For the Generics Explosion
oh!
i feel the same way about them angle brackets!
i'm glad we see eye to eye on this very important point.
Requesting Gravatar... Haacked Oct 28, 2005 10:37 AM
# re: Watch Out For the Generics Explosion
Honey, stay out of this. This is geek talk. We don't need you "cool" people making fun of us. ;)
Requesting Gravatar... Scott Williams Oct 29, 2005 12:06 AM
# re: Watch Out For the Generics Explosion
Generics are probably what I've been most looking forward to in 2.0. I did find a great book talking about the proper way to write code in 2.0. http://www.amazon.com/gp/product/0321246756/104-8807010-1033527?v=glance&n=283155&n=507846&s=books&v=glance
Requesting Gravatar... Rico Mariani Nov 03, 2005 2:51 PM
# re: Watch Out For the Generics Explosion
I believe I said 500 items. :)

Hmmm... my wife doesn't read my blog. I'll have to work on that :)

Bests

What do you have to say?

(will show your gravatar)
Please add 4 and 8 and type the answer here: