Every public change is a breaking change

Here’s an inconvenient truth: just about every “public surface area” change you make to your code is a potential breaking change. First off, I should clarify what I mean by a “breaking change” for the purposes of this article. If you provide a component to a third party, then a “breaking change” is a change…

18

Breaking changes and named arguments

Before I get into the subject of today’s post, thanks so much to all of you who have given us great feedback on the Roslyn CTP. Please keep it coming. I’m definitely going to do some articles on Roslyn in the future; the past few weeks I have been too busy actually implementing it to…

29

Optional argument corner cases, part four

(This is the fourth and final part of a series on the corner cases of optional arguments in C# 4; part three is here.) Last time we discussed how some people think that an optional argument generates a bunch of overloads that call each other. People also sometimes incorrectly think that void M(string format, bool…

18

Asynchrony in C# 5 Part Six: Whither async?

A number of people have asked me what motivates the design decision to require any method that contains an “await” expression to be prefixed with the contextual keyword “async”. Like any design decision there are pros and cons here that have to be evaluated in the context of many different competing and incompossible principles. There’s…

37

A Definite Assignment Anomaly

UPDATE: I have discovered that this issue is considerably weirder than the initial bug report led me to believe. I’ve rewritten the examples in this article; the previous ones did not actually demonstrate the bug.  Consider the following code: struct S {  private string blah;  public S(string blah)  {      this.blah = blah;  }  public void Frob()  {…

22

Why Can’t I Access A Protected Member From A Derived Class? Part Six

Reader Jesse McGrew asks an excellent follow-up question to my 2005 post about why you cannot access a protected member from a derived class. (You probably want to re-read that post in order to make sense of this one.) I want to be clear in my terminology, so I’m going to define some terms. Suppose…

22

Closing over the loop variable, part two

(This is part two of a two-part series on the loop-variable-closure problem. Part one is here.) UPDATE: We are taking the breaking change. In C# 5, the loop variable of a foreach will be logically inside the loop, and therefore closures will close over a fresh copy of the variable each time. The “for” loop…

51

Closing over the loop variable considered harmful

(This is part one of a two-part series on the loop-variable-closure problem. Part two is here.) UPDATE: We are taking the breaking change. In C# 5, the loop variable of a foreach will be logically inside the loop, and therefore closures will close over a fresh copy of the variable each time. The “for” loop…

134

The void is invariant

[UPDATES below]  A while back I described a kind of variance that we’ve supported since C# 2.0. When assigning a method group to a delegate type, such that both the selected method and the delegate target agree that their return type is a reference type, then the conversion is allowed to be covariant. That is,…

21

Reserved and Contextual Keywords

Many programming languages, C# included, treat certain sequences of letters as “special”. Some sequences are so special that they cannot be used as identifiers. Let’s call those the “reserved keywords” and the remaining special sequences we’ll call the “contextual keywords”. They are “contextual” because the character sequence might one meaning in a context where the…

11