Blog - Title

  • Fabulous Adventures In Coding

    Never Say Never, Part One

    Can you find a lambda expression that can be implicitly converted to Func<T> for any possible T? . . . . . . . . . . . Hint : The same lambda is convertible to Action as well. . . . . . . . . . Func<int> function = () => { throw new Exception...
  • Fabulous Adventures In Coding

    Looking inside a double

    Occasionally when I'm debugging the compiler or responding to a user question I'll need to quickly take apart the bits of a double-precision floating point number. Doing so is a bit of a pain, so I've whipped up some quick code that takes a double and...
  • Fabulous Adventures In Coding

    What would Feynman do?

    No one I know at Microsoft asks those godawful "lateral-thinking puzzle" interview questions anymore. Maybe someone still does, I don't know. But rumour has it that a lot of companies are still following the Microsoft lead from the 1990s in their interviews...
  • Fabulous Adventures In Coding

    Optional arguments on both ends

    Before we get into today's topic, a quick update on my posting from last year about Roslyn jobs. We have gotten a lot of good leads and made some hires but we still have positions open, both on the Roslyn team and on the larger Visual Studio team. For...
  • Fabulous Adventures In Coding

    Strange, but legal

    "Can a property or method really be marked as both abstract and override?" one of my coworkers just asked me. My initial gut response was "of course not!" but as it turns out, the Roslyn codebase itself has a property getter marked as both abstract and...
  • Fabulous Adventures In Coding

    Curiouser and curiouser

    Here's a pattern you see all the time in C#: class Frob : IComparable<Frob> At first glance you might ask yourself why this is not a "circular" definition; after all, you're not allowed to say " class Frob : Frob "(*). However, upon deeper reflection...
  • Fabulous Adventures In Coding

    Spot the defect: Bad comparisons, part four

    One more easy one. I want to "sort" a list into a random, shuffled order. I can do that by simply randomizing whether any two elements are greater than, less than, or equal to each other: myList.Sort((x, y) => (new Random()).Next(-1, 2)); That generates...
  • Fabulous Adventures In Coding

    Spot the defect: Bad comparisons, part three

    Did you notice how last time my length comparison on strings was unnecessarily verbose? I could have written it like this: static int ByLength(string x, string y) { if (x == null && y == null) return 0: if (x == null) return -1; if (y == null...
  • Fabulous Adventures In Coding

    Spot the defect: Bad comparisons, part two

    Suppose I want to sort a bunch of strings into order first by length, and then, once they are sorted by length, sort each group that is the same length by some other comparison. We can easily build such a device with higher-order programming: static Comparison<string>...
  • Fabulous Adventures In Coding

    Spot the defect: Bad comparisons, part one

    The mutable List<T> class provides an in-place sort method which can take a comparison delegate. It's quite handy to be able to sort a list into order by being able to compare any two elements, but you have to make sure you get it right. First off...
  • Fabulous Adventures In Coding

    Not as easy as it looks, Part Two

    Holy goodness, did you guys ever find a lot of additional ways in which an "eliminate variable" refactoring can go wrong. Just a few of your observations: (again, in every case, "x" is eliminated.) Any situation in which x is being treated as a variable...
  • Fabulous Adventures In Coding

    Not as easy as it looks

    My colleague Kevin works on (among many other things) the refactoring engine in the C# IDE. He and I were at the end of last year discussing the possible cases for a hypothetical "eliminate variable" refactoring. I thought that it might be of interest...
  • Fabulous Adventures In Coding

    Enormous Explosions

    Welcome to 2011 everyone; I hope you all had as restful a time as I did over the winter break. We’ll get back into language and tools design next time; today’s post is dedicated to the memory of my friend Frank, an old and dear friend of my whole family...
  • Fabulous Adventures In Coding

    Why are anonymous types generic?

    Suppose you use an anonymous type in C#: var x = new { A = "hello", B = 123.456 }; Ever taken a look at what code is generated for that thing? If you crack open the assembly with ILDASM or some other tool, you'll see this mess in the top-level type definitions...
  • Fabulous Adventures In Coding

    Hiring for Roslyn

    A couple years ago I made a blog posting called "The Managed Languages Team Is Hiring" mere hours before our senior management announced that our hiring goals had been met and told me to please stop recruiting people. That was a little embarrassing ....
  • Fabulous Adventures In Coding

    All your base do not belong to you

    People sometimes ask me why you can’t do this in C#: class GrandBase { public virtual void M() { Console.WriteLine("GB"); } } class Base : GrandBase { public override void M() { Console.WriteLine("B"); } } class Derived : Base { public override void M...
  • Fabulous Adventures In Coding

    Big head, long tail

    Here's a graph of the population size of the one hundred largest urban areas in Canada : (Click on the graph for a larger version.) Notice how there is an enormous spiky "head" on this graph: Toronto, Montreal and Vancouver are quite large cities...
  • Fabulous Adventures In Coding

    Bit twiddling: What does warning CS0675 mean?

    From the sublime level of continuation passing style we go back to the mundane level of twiddling individual bits. int i = SomeBagOfBits(); ulong u = SomeOtherBagOfBits(); ulong result = u | i; // combine them together Whoops, that's an error. "Operator...
  • Fabulous Adventures In Coding

    Asynchrony in C# 5, Part Eight: More Exceptions

    (In this post I'll be talking about exogenous , vexing , boneheaded and fatal exceptions. See this post for a definition of those terms .) If your process experiences an unhandled exception then clearly something bad and unanticipated has happened. If...
  • Fabulous Adventures In Coding

    Asynchrony in C# 5, Part Seven: Exceptions

    Resuming where we left off (ha ha ha!) after that brief interruption: exception handling in "resumable" methods like our coroutine-like asynchronous methods is more than a little bit weird. To get a sense of how weird it is, you might want to first refresh...
  • Fabulous Adventures In Coding

    The Annotated Fourth Edition is available

    A brief digression from C# 5 to talk about C# 4: the annotated C# 4 specification is now available in book form from Addison-Wesley . It is of course handy to have a specification in book form, particularly if you're going to while away the hours with...
  • Fabulous Adventures In Coding

    Asynchrony in C# 5 Part Six: Whither async?

    A number of people have asked me what motivates the design decision to require any method that contains an "await" expression to be prefixed with the contextual keyword "async". Like any design decision there are pros and cons here that have to be evaluated...
  • Fabulous Adventures In Coding

    Asynchrony in C# 5 Part Five: Too many tasks

    Suppose a city has a whole bunch of bank branches, each of which has a whole bunch of tellers and one gofer. There are a whole bunch of customers in the city, each of whom wants to withdraw a whole bunch of money from the bank at some varying time throughout...
  • Fabulous Adventures In Coding

    Asynchrony in C# 5.0 part Four: It's not magic

    Today I want to talk about asynchrony that does not involve any multithreading whatsoever. People keep on asking me "but how is it possible to have asynchrony without multithreading?" A strange question to ask because you probably already know the answer...
  • Fabulous Adventures In Coding

    Asynchrony in C# 5, Part Three: Composition

    I was walking to my bus the other morning at about 6:45 AM. Just as I was about to turn onto 45th street, a young man, shirtless, covered in blood ran down 45th at considerable speed right in front of me. Behind him was another fellow, wielding a baseball...
Page 5 of 32 (783 items) «34567»