Watch Out For the Generics Explosion

0 comments suggest edit

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.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

4 responses

  1. Avatar for wife
    wife October 27th, 2005

    oh!

    i feel the same way about them angle brackets!

    i'm glad we see eye to eye on this very important point.

  2. Avatar for Haacked
    Haacked October 27th, 2005

    Honey, stay out of this. This is geek talk. We don't need you "cool" people making fun of us. ;)

  3. Avatar for Scott Williams
    Scott Williams October 28th, 2005

    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

  4. Avatar for Rico Mariani
    Rico Mariani November 3rd, 2005

    I believe I said 500 items. :)



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



    Bests