Browse by Tags

Tagged Content List
  • Blog Post: Dynamic contagion, part two

    Last time I discussed how "dynamic" tends to spread through a program like a virus : if an expression of dynamic type "touches" another expression then that other expression often also becomes of dynamic type. Today I want to describe one of the least well understood aspects of method type inference...
  • Blog Post: How do we ensure that method type inference terminates?

    I missed the party. I was all set to be on that massive wave of announcements about TypeScript , and then a family emergency kept me away from computers from Thursday of last week until just now, and I did not get my article in the queue. Suffice to say that I am SUPER EXCITED about TypeScript. Long...
  • Blog Post: Foolish consistency is foolish

    Once again today's posting is presented as a dialogue, as is my wont. Why is var sometimes required on an implicitly-typed local variable and sometimes illegal on an implicitly typed local variable? That's a good question but can you make it more precise? Start by listing the situations in which an implicitly...
  • Blog Post: Why not automatically infer constraints?

    UPDATE: Whoops! I accidentally set a draft of this article to automatically publish on a day that I was away on vacation. The fact that it was (1) not purple and (2) introduced the topic and then stopped in mid-sentence were both clues that this was an unfinished edit. Sorry about that; I thought I had...
  • Blog Post: Uses and misuses of implicit typing

    One of the most controversial features we've ever added was implicitly typed local variables , aka "var". Even now, years later, I still see articles debating the pros and cons of the feature. I'm often asked what my opinion is, so here you go. Let's first establish what the purpose of code is in the...
  • Blog Post: Why are anonymous types generic?

    Suppose you use an anonymous type in C#: var x = new { A = "hello", B = 123.456 }; Ever taken a look at what code is generated for that thing? If you crack open the assembly with ILDASM or some other tool, you'll see this mess in the top-level type definitions .class '<>f__AnonymousType0`2'<...
  • Blog Post: 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...
  • Blog Post: Why no var on fields?

    In my recent request for things that make you go hmmm, a reader notes that you cannot use "var" on fields. Boy, would I ever like that. I write this code all the time: private static readonly Dictionary<TokenKind, string> niceNames = new Dictionary<TokenKind, string>() { {TokenKind.Integer...
  • Blog Post: 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...
  • Blog Post: Method Type Inference Changes, Part Zero

    Back in November I wrote a bit about a corner case in method type inference which does not work as expected or as specified in C# 3.0. A number of people made blog comments, sent me mail, and entered "Connect" issues with additional problems and ideas for how we could improve this algorithm. (Particular...
  • Blog Post: C# 3.0 Return Type Inference Does Not Work On Method Groups

    UPDATE : A lot of people have linked to this article which is somewhat out of date now. This article describes why in C# 3.0, return type inference does not work when the argument is a method group and the formal parameter is a generic delegate. As you can see, there was a lot of feedback on this article;...
  • Blog Post: Lambda Expressions vs. Anonymous Methods, Part Two

    We interrupt the discussion of how the difference between lambda expression and anonymous method convertibility leads to potential performance problems in the compiler to answer a user question. Within hours of yesterday's post readers Raymond Chen and Marc Brooks both asked me the same question....
  • Blog Post: A Face Made For Email, Part Three

    Yes, it has happened again . This time, our fabulous C# Community Program Manager Charlie Calvert was good enough to put together a little half-hour-long video of me talking about the scenarios which justify changes to the type inference algorithm for C# 3.0. We've already made some interesting changes...
  • Blog Post: Type inference woes, part four

    Last time in this series I discussed how we are probably going to identify a "best" type from a set of expressions. Clearly we need to solve this problem for features such as implicitly typed arrays. We are also considering extending this algorithm to affect type inference of generic methods. As always...
  • Blog Post: What Are The Semantics Of Multiple Implicitly Typed Declarations? Part Two

    Many thanks for all your input in my informal poll yesterday. The results were similar to other "straw polls" we've done over the last couple of months. In this particular poll the results were: var a=A, b=B; where the expressions are of different types should: have the same semantics as var...
  • Blog Post: What Are The Semantics Of Multiple Implicitly Typed Declarations? Part One

    In my earlier series on inferring a unique "best" type from a set of expressions I mentioned that one potential application of such an algorithm is in implicitly typed variables. This led to some good questions and concerns posted in the comments - questions and concerns which echo similar feedback we...
  • Blog Post: Type inference woes, part three

    There were a lot of good comments and questions posted in the last two entries which deserve answers. However, I am once more off to the beaver-shark infested shores of the great Canadian inland sea for my annual summer vacation. I'll get to them when I'm back, in late June. Before I go I should mention...
  • Blog Post: Type inference woes, part two

    So what's the big deal anyway? The difference between the spec and the implementation is subtle, only affects a few specific and rather unlikely scenarios, and can always be worked around by inserting casts if you need to. Fixing the implementation would be a breaking change, it seems like a small and...
  • Blog Post: Type inference woes, part one

    The C# compiler has a subtle violation of the specification which raises an interesting question for some of the new LINQ-related features. The specification for the ?: operator states the following: The second and third operands of the ?: operator control the type of the conditional expression...
  • Blog Post: Delegates, Lambdas, Type Inference and Long Playing Records

    Today is my 33 1/3rd birthday! I'm one third of the way through my first century. I feel like I should go buy some LPs to celebrate, not that I have anything that will play them. In other news, someone sent me this code the other day. Suppose you've got a collection of mammals and you want to feed...
  • Blog Post: C# 3.0 is still statically typed, honest!

    Since LINQ was announced I've seen a lot of really positive feedback and a lot of questions and concerns. Keep 'em coming! We need this feedback so that we can both correct misconceptions early and get the design right now. One of the misconceptions that I've seen a lot over the last few days in forums...
Page 1 of 1 (21 items)