The Johnson Blog

Ramblings of a geek with a few hobbies…

  • C# operator== overloading

    I recently came to a situation where operator overloading C# (specifically the == operator) would really be beneficial. Since I’ve typically steered away from this technique, for readability and maintainability, I hadn’t had much experience with it.

    My overloaded operator looks something like this:


    static bool operator==(Id<T> a, Id<T> b)
    {
    return a.Value == b.Value;
    }

    That has been working just as planned for a few months now, but today I hit a snag when trying to do a null test against a variable of that class type, like:


    Id<int> x;
    ...
    if (x == null)
    {
    ...
    }

    This causes a nice null reference exception at a.Value because a is null. My first thought was to test for null in the operator== method before I attempt accessing a.Value (or b.Value), like:

    if (a == null)
    {
    return b == null;
    }
    else
    {
    return a.Value == b.Value;
    }

    Thinking I had the problem fixed, I reran; and quickly hit a StackOverFlowException. What the? Ooooh, the if (a == null) was causing that method to be called over and over, recursively until it blew the stack! OK, now how the heck can I test against null without the operator== being called??

    After a moment of slight panic, I realized how to get around it. When doing just if (a == null), the Id class’ static overload is being called. The way out of this is to have the object class’ operator== explicitly called by making a simple change:


    if ((object)a == null)
    {
    return ((object)b == null);
    }
    else
    {
    return a.Value == b.Value;
    }

    And that’s it! I now have an overload that handles null checking.

  • Blood Test

    Ana has a blood test scheduled for 8am tomorrow morning.  We’ll see if the last visit did any good.  Stay tuned for more information.

  • New Url!

    You’ll notice the blog has a new domain, http://www.thejohnsonblog.com.  Please update your links and bookmarks accordingly.

    The migration went well, I think I got all internal links modified.  We’ll see!

  • Almost…

    We’re staring at the last few drops of the IVIG dripping one by one. Just a few more minutes….

    Let me take this time to describe the wonderful view outside this room. It’s dark, dreary and rainy. Scanning from left to right, 9 floors up, we have: the hospital parking garage, the red EMergENCY room sign (“erg” aren’t lit up), the 9th street entrance under construction and blocked off, the big old abandoned Pillsbury plant, an enormous puddle-filled parking lot, the Carol Jo Vecchie center with their nice rooms, lots of air conditioning units atop a roof, the unused medical incinerator smokestack, and finally the power plant construction at CWLP.

    I can’t see Smokey Bones from here… that’s a shame. We’ll be there soon for some dinner and some SWEET TEA!

  • Platelets, check.

    The platelet infusion is done.  Now it’s on to the 3 hours of IVIG.

  • Information

    Katherine recommended this site, and I thought I’d pass it along as it seems to be full of lots of good information regarding platelet disorders in general and specifically ITP.

  • Here we are again..

    This morning, Ana had a scheduled blood test (due to our last hospital stay) that came back quite unfavorably with her platelet counts at 7,000.  So they had her come into the hospital to get another platelet transfusion as well as a dosage of IVIG.

    This is the outpatient floor of the hostpital so they are insisting that we’ll be out of here tonight.  It’ll be a while though – she’s currently getting her platelets infused at a rate that will take 2 hours; following that will be the IVIG that will take another 3 hours.

    We haven’t really spoken to any doctors, which is pretty annoying.  This has all been handed down by one, obviously, through the various nurses.

    She’s not in the comfortable Carol Jo Vecchie center, so the rooms aren’t nearly as comfortable and she’s got a roommate.  Keep checking back for updates, I have a nice broadband connection here in the room thanks to Jay.

  • Depth of Field

    F1.4 – a pretty good example of a very shallow depth of field.  It’s probably around 1″ or so, try doing that with a Point-n-Shoot camera!

    SpoonRiverDrive-19.jpg

  • Canon 30D

    I’m bored, so I decided to post a small, 100% crop from my 30D.  This guy passed us in a semi going the opposite direction on a rural highway, both of us going probably 65 or so.  This is a testament to the awesome focusing capabilities of the 30D in AI mode.
    CanonCrop.jpg

    Yeah, I love my camera.