Browse by Tags

Tagged Content List
  • Blog Post: 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...
  • Blog Post: 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 { /* ... */ } void M<X>...
  • Blog Post: 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 that same program...
  • Blog Post: 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...
  • Blog Post: 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 of the gate, because I am...
  • Blog Post: 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)...
  • Blog Post: 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 looking forward...
  • Blog Post: 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...
  • Blog Post: 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);...
  • Blog Post: Spoiler Alert

    The remaining video of the talk with Neal Gafter and me at NDC is up on the streaming content server now, here . However, spoiler alert: if you don't want to know the solutions to the eight puzzles we present, don't watch the video. Of course, long time readers of this blog have probably seen about...
  • Blog Post: Murky Research

    No computers today, but some interesting - and important - math. (And, happy Canada Day, Canadians!) " Car Talk " is a popular weekly phone-in program that has been on National Public Radio for several decades now, in which Bostonian brothers Tom and Ray crack wise and diagnose car (and relationship...
  • Blog Post: Always write a spec, part one

    Joel had a great series of articles many years ago about the benefits of writing functional specifications , that is, specifications of how the product looks to its users. I want to talk a bit about technical specifications, that is, a specification of how something actually works behind the scenes....
  • Blog Post: Simple names are not so simple, Part Two, plus, volcanoes and fried foods

    I've returned from a brief vacation, visiting friends on the island of Maui. I'd never been to that part of the world before. Turns out, it's a small island in the middle of the Pacific Ocean, entirely made out of volcanoes. Weird! But delightful. The most impressive thing about the Hawaiian Islands...
  • Blog Post: Simple names are not so simple

    C# has many rules that are designed to prevent some common sources of bugs and encourage good programming practices. So many, in fact, that it is often quite confusing to sort out exactly which rule has been violated. I thought I might spend some time talking about what the different rules are. We'll...
  • Blog Post: 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"); } } ...
  • Blog Post: What Would Tufte Do?

    What is this a chart of? I'll post the answer tomorrow. UPDATE: Someone has already correctly deduced the answer. (And man, that was fast!) So don't read the comments if you don't want spoilers.
  • Blog Post: Comma Quibbling

    [UPDATE: Holy goodness. Apparently this was a more popular pasttime than I anticipated. There's like a hundred solutions in there. Who knew there were that many ways to stick commas in a string? It will take me some time to go through them all, so don't be surprised if it's a couple of weeks until I...
  • Blog Post: Mutating Readonly Structs

    Consider this program which attempts to mutate a readonly mutable struct. What happens? struct Mutable { private int x; public int Mutate() { this.x = this.x + 1; return this.x; } } class Test { public readonly Mutable m = new Mutable(); static void Main(string[] args) { Test t = new Test(); System...
  • Blog Post: Why Do Initializers Run In The Opposite Order As Constructors? Part Two

    As you might have figured out, the answer to last week's puzzle is "if the constructors and initializers run in their actual order then an initialized readonly field of reference type is guaranteed to be non null in any possible call. That guarantee cannot be met if the initializers run in the expected...
  • Blog Post: Why Do Initializers Run In The Opposite Order As Constructors? Part One

    Pop quiz! What do you expect the output of this program to be? using System; class Foo { public Foo(string s) { Console.WriteLine("Foo constructor: {0}", s); } public void Bar() { } } class Base { readonly Foo baseFoo = new Foo("Base initializer"); public Base() { Console.WriteLine("Base...
  • Blog Post: Psychic Debugging, Part Two

    A number of readers have the mysterious fifth sense which gives them the ability to deduce that the GetBars method from yesterday's post contains a yield return and is therefore an iterator. Remember, as the standard states (in section 10.14.4): [...] execution of the code in the iterator block occurs...
  • Blog Post: Psychic Debugging, Part One

    Here is a compiler bug report I got the other day. The user is trying to write a unit test for a method which takes a Foo and returns a collection of Bar s. The test is supposed to confirm that GetBars throws an exception if the argument is null . The test was failing with “got no exception”. The user...
  • Blog Post: An Inheritance Puzzle, Part Two

    Today, the answer to Friday's puzzle . It prints "Int32". But why? Some readers hypothesized that M would print out "Int32" because the declaration B : A<int> somehow tells B that T is to be treated as int , now and forever. Though the answer is right, the explanation is not quite right. One...
  • Blog Post: An Inheritance Puzzle, Part One

    Once more I have returned from my ancestral homeland, after some weeks of sun, rain, storms, wind, calm, friends and family. I could certainly use another few weeks, but it is good to be back too. Well, enough chit-chat; back to programming language design. Here's an interesting combination of subclassing...
  • Blog Post: Even More Conversion Trivia, Part Two

    Reader Barry Kelly came up with the solution I was thinking of for my trivia question yesterday. If the value in question is, say, a nullable integer which has no value then casting it explicitly to object results in the null object. Calling a virtual method on a null object results in an exception at...
Page 1 of 3 (52 items) 123