New, Var, the Chicken and the Egg

by casperOne 27. January 2009 12:16

Eric Lippert's most recent blog entry proposed an interesting suggestion for enhancing the C# language:

If our goal is to remove the redundancy, I would therefore prefer to remove it the other way. Make this legal:

private static readonly Dictionary<TokenKind, string> niceNames = new()...

That is, state the type unambiguously in the declaration and then have the "new" operator be smart about figuring out what type it is constructing based on what type it is being assigned to. This would be much the same as how the lambda operator is smart about figuring out what its body means based on what it is being assigned to.

I can't tell you how much I love this.  While I absolutely love the var keyword in C#, there is a massive potential for abuse here.  It is too easy to use it to obfuscate code and use it in situations where you don’t need it (you need it when generating an anonymous type, most often for projections in LINQ).

I love it so much that I’ve already suggested it to Microsoft at least a year ago.

Last year, at the MVP Global Summit, I proposed this idea to Mads Torgersenafter his presentation on possible future enhancements to the C# language.  This conversation resulted in a very long email that was sent to Mads on the subject, which I had hoped would result in its distribution inside Microsoft for discussion.

I even made a suggestion through the Microsoft Connect site, elaborating on the language feature, as well as it’s impact (or lack thereof on existing code).  The suggestion can be found here:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=388649

Addtionally, I posted the link in the microsoft.public.dotnet.csharp newsgroup, asking for comments on the recommendation as well.  The full thread can be found here:

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/f8ab748deca4737

Needless to say, I’m a bit frustrated about the situation, given that there is no reference to the email, or the suggestion, both of which predated his blog post.

Of course, I’m completely cognizant of the fact ideas are a spontaneous thing and that the same ones can sprout anywhere.

However, what is frustrating to me is that this idea is coming from a person in the organization and on the team in that organization that I submitted the idea to, and that kind of coincidence is suspicious, at best.

Oh, and I will post the full details of the idea at a later date.

Tags: , , ,

programming