There’s a hole in my abstraction, dear Liza, dear Liza

I had an interesting day at work today. I thought my code had broken… but it turns out it was just a strange corner case which made it work very slowly. Usually when something interesting happens in my code it’s quite hard to blog about it, because of all the confidentiality issues involved. In this case, it’s extremely easy to reproduce the oddity in an entirely vanilla manner. All we need is the Java collections API. I have a set – a HashSet, in fact. I want to remove some items from it… and many of the items may well … Continue reading There’s a hole in my abstraction, dear Liza, dear Liza

Iterate, damn you!

Do you know the hardest thing about presenting code with surprising results? It’s hard to do so without effectively inviting readers to look for the trick. Not that that’s always enough – I failed the last of Neal and Eric’s C# puzzlers at NDC, for example. (If you haven’t already watched the video, please do so now. It’s far more entertaining than this blog post.) Anyway, this one may be obvious to some of you, but there are some interesting aspects even when you’ve got the twist, as it were. What does the following code print? using System; using System.Collections.Generic; … Continue reading Iterate, damn you!

Degrees of reality in sample code

Yesterday I tweeted a link to an article about overloading that I’d just finished. In that article, all my examples look a bit like this: using System; class Test {     static void Foo(int x, int y = 5)     {         Console.WriteLine("Foo(int x, int y = 5)");     }          static void Foo(double x)     {         Console.WriteLine("Foo(double x)");     }     static void Main()     {         Foo(10);     } } Each example is followed by an explanation of the output. Fairly soon afterwards, I received an email from a reader who disagreed with my choices for sample code. ere … Continue reading Degrees of reality in sample code

How many Jedi?

(There’s no technical content in this post… but you may get a bit of a giggle from it. When I get the second edition web site notes together I’ll include this as well… but I thought it was fun enough to deserve a blog post too.) The second edition of C# in Depth is nearing the end of its technical review cycle, as performed by the great Eric Lippert. Yesterday I received the comments for chapter 13, which includes this section heading: The revenge of optional parameters and named arguments Now, my copy editor (Ben) wasn’t too keen on this. … Continue reading How many Jedi?