The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Latent Typing and Generics

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brad Wilson

Posts: 462
Nickname: dotnetguy
Registered: Jul, 2003

Brad Wilson is CTO of OneVoyce, Inc.
Latent Typing and Generics Posted: Jan 3, 2005 8:43 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Brad Wilson.
Original Post: Latent Typing and Generics
Feed Title: The .NET Guy
Feed URL: /error.aspx?aspxerrorpath=/dotnetguy/Rss.aspx
Feed Description: A personal blog about technology in general, .NET in specific, and when all else fails, the real world.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Brad Wilson
Latest Posts From The .NET Guy

Advertisement

Charles Cook gets why I'm aggrevated with .NET generics. Using his examples, let's make the leap he didn't show.

In C++ you can do this, but in .NET you can't:

class TestClass<T>
{
    public void Foo(T t)
    {
        t.Bar();
    }
}

This is exactly what I mean about "latent typing". The C++ compiler doesn't care what type T is, as long as you can call Bar() on it. Using the generics system in .NET 2.0, you have to write something like:

interface IBar
{
    void Bar();
}

class TestClass<T> where T : IBar
{
    public void Foo(T t)
    {
        t.Bar();
    }
}

What Charles didn't point out is that there's absolutely no point for generics here now. You can write this, today, in .NET 1.x, and get the same thing:

class TestClass
{
    public void Foo(IBar t)
    {
        t.Bar();
    }
}

And now it's less confusing. This leads me to the conclusion that generics, as implemented in .NET, are only good for a single class of problem: that is, problems where you don't actually USE the type in question. What kinds of problems are that? Well, basically, containers.

The generic system in .NET was designed solely to support performant, cast-free containers (a solution we could already solve well with code generation). The power and beauty of latent typed generic programming is completely absent from the generics solution in .NET.


This content is syndicated from The .NET Guy. The original post is Latent Typing and Generics.

The opinions expressed herein are solely those of Brad Wilson, and not meant as an endorsement of or by any other individuals or groups. This syndication is provided for the private, personal use of individuals. Unauthorized commercial reproduction is strictly prohibited.

Read: Latent Typing and Generics

Topic: Geek Notes 2004-12-31 Previous Topic   Next Topic Topic: Subversion Support in the Resharper IDE

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use