A method group of one

I’m implementing the semantic analysis of dynamic expressions in Roslyn this week, so I’m fielding a lot of questions within the team on the design of the dynamic feature of C# 4. A question I get fairly frequently in this space is as follows: public class Alpha{  public int Foo(string x) { … }}…dynamic d…

8

Optional arguments on both ends

Before we get into today’s topic, a quick update on my posting from last year about Roslyn jobs. We have gotten a lot of good leads and made some hires but we still have positions open, both on the Roslyn team and on the larger Visual Studio team. For details, see this post on the Visual…

23

Constraints are not part of the signature

What happens here? class Animal { } class Mammal : Animal { } class Giraffe : Mammal { }class Reptile : Animal { } …static void Foo<T>(T t) where T : Reptile { }static void Foo(Animal animal) { }static void Main() {     Foo(new Giraffe()); } Most people assume that overload resolution will choose the…

122

What’s the difference, part one: Generics are not templates

Because I’m a geek, I enjoy learning about the sometimes-subtle differences between easily-confused things. For example: I’m still not super-clear in my head on the differences between a hub, router and switch and how it relates to the gnomes that live inside of each. Hunks of minerals found in nature are rocks; as soon as you…

32

Color Color

Pop quiz: What does the following code do when compiled and run? class C{    public static void M(string x)    {        System.Console.WriteLine(“static M(string)”);    }    public void M(object s)    {        System.Console.WriteLine(“M(object)”);    } }class Program{    static void Main()    {        C c = new C();        c.M(“hello”);    }} (1) writes static M(string)(2) writes M(object)(3) uh, dude, this code doesn’t even…

24

Method Type Inference Changes, Part One

I want to start this by discussing the purpose of method type inference, and clearing up some potential misunderstandings about type inference errors. First off though, a brief note on nomenclature. Throughout this series when I say “type inference” I mean “method type inference”, not any of the other forms of type inference we have…

9

Future Breaking Changes, Part Two

Last time I mentioned that one of the subtleties of programming language design is weighing the benefit of adding a feature against the pain it will cause you in the future. This is a specific subset of a more general set of problems. Languages run into the same problem that other large, multiply-versioned software products run…

9

Lambda Expressions vs. Anonymous Methods, Part Five

Last time I demonstrated that the compiler could have to do an exponential number of bindings in order to determine whether there was a unique best overload resolution for a function call that takes a lambda. Some of you may have wondered whether we simply were not being clever enough in the compiler. Perhaps there…

6

Lambda Expressions vs. Anonymous Methods, Part Four

Hey all, sorry for the long time between posts; I have been crazy busy recruiting, interviewing, fixing bugs, making performance improvements and implementing last-minute changes to the language and expression tree library. The last few posts about lambda binding yielded many interesting comments which I hope to address over the next month or so. Before…

9

Odious ambiguous overloads, part one

As you might have gathered, a lot of the decisions we have to make day-to-day here involve potential breaking changes on odd edge cases. Here’s another one. Consider the following terrible but legal code: public interface I1<U> {    void M(U i);    void M(int i);} My intense pain begins when the user writes: public class C1 :…

9