Roslyn September 2012 CTP is now available

I am super excited to announce that we have just released a third “Community Technology Preview” of Roslyn. Roslyn, in case you have not heard, is the code name for the project I work on; we are re-architecting the C# and VB compilers so that they are no longer “black boxes” where code goes in,…

9

Static analysis of "is"

Before I get into the subject of today’s fabulous adventure, I want to congratulate the whole rest of Developer Division on the tremendously exciting product that we are formally launching today. (I’ve done very little actual coding on Visual Studio 2012 and C# 5.0, being busy with the long-lead Roslyn project.) Asynchronous programming support in…

5

An "is" operator puzzle, part two

As I said last time, that was a pretty easy puzzle: either FooBar, or the type of local variable x, can be a type parameter. That is: void M<FooBar>(){  int x = 0;  bool b = x is FooBar;  // legal, true if FooBar is int.  FooBar fb = (FooBar)x; // illegal} or struct FooBar…

13

Fabulous Adventures In Casting

I’ve written a lot about casting over the years in this blog, but always in the context of the “cast operator”: the operator that instructs the compiler to make an explicit conversion from a value of one type to a value of another type. I have recently taken up a new hobby that is casting…

3

An "is" operator puzzle, part one

It is possible for a program with some local variable x: bool b = x is FooBar; to assign true to b at runtime, even though there is no conversion, implicit or explicit, from x to FooBar allowed by the compiler! That is, FooBar foobar = (FooBar)x; would not be allowed by the compiler in…

21

Wackiness ensues

No tech today, but this is too funny to not pass along, so consider this your fun for Friday. What would happen if Anders Hejlsberg and Barbara Liskov were forced to share an apartment in an “odd couple” sitcom? (*) Apparently I’m the “Kramer” of this sitcom. I hope I’m played by Ryan Gosling. Additional…

8

Out parameters and LINQ do not mix

I am back from my annual vacation in beautiful southwestern Ontario; before I get into the subject of today’s post, check out this shot I took with my Windows Phone camera from the plane on the trip home. We are at 37000 feet, just outside of Billings, Montana, a few minutes before sunset: The whole…

28

Should C# warn on null dereference?

As you probably know, the C# compiler does flow analysis on constants for the purposes of finding unreachable code. In this method the statement with the calls is known to be unreachable, and the compiler warns about it. const object x = null;void Foo(){  if (x != null)  {    Console.WriteLine(x.GetHashCode());  }} Now suppose we removed…

35

When is a cast not a cast?

I’m asked a lot of questions about conversion logic in C#, which is not that surprising. Conversions are common, and the rules are pretty complicated. Here’s some code I was asked about recently; I’ve stripped it down to its essence for clarity: class C<T> {}class D{  public static C<U> M<U>(C<bool> c)  {    return something;  }}public…

26

The Best Advice I Ever Got

Just a quick link today: The super nice people over at InformIT (*) are running a series of short articles with the theme “the best advice I ever got”, which I think should prove to be an interesting series. They were kind enough to ask me to give an example of some good advice I…

11