## 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…

## 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…

## 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…

## A brief digression

Before we continue our exploration of truthiness in C#, a brief digression. I mentioned last time the “knights and knaves” puzzles of logician Raymond Smullyan. Though I do enjoy those puzzles, my favourite of his puzzles are his chess puzzles, and my second favourite are his combinatory logic puzzles. Here’s an example of the latter,…

## The Solution To The Simple Puzzle

The first time I ran my histogram visualizer I asked for a Cauchy distribution with a minimum of -10 and a maximum of 10, and of course I got a graph that looks much like the one from my article of last week:   Looks perfectly reasonable; I guess my program is correct right out…

## A Simple Puzzle

My original version of the histogram-generating code that I whipped up for the previous episode of FAIC contained a subtle bug. Can you spot it without going back and reading the corrected code? private static int[] CreateHistogram(IEnumerable<double> data, int buckets, double min, double max){  int[] results = new int[buckets];  double multiplier = buckets / (max…

## The curious property revealed

Today is the fifteenth anniversary of my first day of full time work here at Microsoft. Hard to believe it has been a decade and a half of writing developer tools. I am tremendously fortunate to be able to work with such a great team on such a great toolset for such great customers. I’m…

## What curious property does this string have?

There are all kinds of interesting things in the Unicode standard. For example, the block of characters from U+A000 to U+A48F is for representing syllables in the “Yi script”. Apparently it is a Chinese language writing system developed during the Tang Dynasty. A string drawn from this block has an unusual property; the string consists…

## To box or not to box, that is the question

Suppose you have an immutable value type that is also disposable. Perhaps it represents some sort of handle. struct MyHandle : IDisposable{    public MyHandle(int handle) : this() { this.Handle = handle; }    public int Handle { get; private set; }    public void Dispose()    {        Somehow.Close(this.Handle);    }} You might think hey, you know, I’ll decrease my…