Fabulous Adventures In Coding

Eric Lippert's Blog

Browse by Tags

Tagged Content List
  • 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...
  • Blog Post: Even More Conversion Trivia

    I learn something new about C# every day. This is a subtle and tricky language. Pop quiz: foo is of a type which has a base class which has made a normal, everyday virtual override of System.Object.ToString . There are no additional overrides, hides, etc of ToString anywhere in foo 's inheritance...
  • Blog Post: Chained user-defined explicit conversions in C#, Part Three

    Jeroen Frijters knew the answer to my challenge of last time: how is it that Foo foo = new Foo(); can cause a runtime conversion failure? And how is it that Bar bar = (Bar)(new Baz()); can succeed even if there is no user-defined conversion or built-in implicit conversion between Baz and Bar ? The...
  • Blog Post: Chained user-defined explicit conversions in C#, Part Two

    Reader Larry Lard asks a follow-up question regarding the subject of Monday’s blog entry . Why is it that the compiler knows that (int)(new Base()) will always fail, and therefore makes the conversion illegal, but does not know that (Derived)(new Base()) will always fail, and make that conversion illegal...
  • Blog Post: Practice thinking like a compiler tester, part three

    Yesterday I posed a slightly harder version of the puzzle I posted the day before . Reader Steve found a solution: public class C : A {} public class A { public class D : C {} } See his comment for the trace of the logic that shows why this asserts. The scenario that our testers found which...
  • Blog Post: Practice thinking like a compiler tester, part two

    Reader RichM found the same solution to the puzzle I posed yesterday that I did: public class V : S.T {} public class S { public class T{} } The control flow of the emitter from the start to the point of the bug goes like this: Emit(V) Emit (S.T) // V base class Emit(null) // S.T base class...
  • Blog Post: Practice thinking like a compiler tester

    I don’t know why but for some reason I find this little recursive algorithm I ran across in the compiler the other day to be completely hilarious. For every class in your program we have to emit metadata. For various historical reasons, there are strict rules we must follow about the order in which...
Page 1 of 2 (46 items) 12