Today a follow-up to my 2010 article about the meaning of the
is operator. Presented as a dialog, as is my wont!
I’ve noticed that the
is operator is inconsistent in C#. Check this out:
string s = null; // Clearly null is a legal value of type string
bool b = s is string; // But b is false!
What’s up with that?
Let’s suppose you and I are neighbours.
Um… ok, I’m not sure where this is going, but sure.
I can’t believe it took almost ten years, but someone just asked me for the first time where the name of this blog comes from. Why “fabulous adventures”?
Today on FAIC, a detective story.
Part two of my Tech.pro beginner-level series on how to write bad benchmarking code can be found here.
Happy Eliza Doolittle day all; today seems like an appropriate day for careful elocution of technical jargon. So today, yet another question about “scope”. As one of the more over-used jargon terms in programming languages, I get a lot of questions about it.
I’ll remind you all again that in C# the term “scope” has a very carefully defined meaning: the scope of a named entity is the region of program text in which the unqualified name can be used to refer to the entity.[1. Scope is often confused with the closely related concepts of declaration space (the region of code in which no two things may be declared to have the same name), accessibility domain (the region of program text in which a member’s accessibility modifier permits it to be looked up), and lifetime (the portion of the execution of the program during which the contents of a variable are not eligable for garbage collection.)]
Some fun for Friday. I just opened up a box containing a brand-new bit of telecommunications equipment, and the power supply arrived looking like this, fresh out of the box. (Click for a larger version.)
How bad does your quality assurance have to be to ship to customers a power supply that cannot possibly fit into a power socket?
Last time I challenged you to find a value which does not round correctly using the algorithm
Math.Floor(value + 0.5)
The value which does not round correctly is the double
0.49999999999999994, which is the largest double that is smaller than
0.5. With the given algorithm this rounds up to
1.0, even though clearly
0.49999999999999994 is less than one half, and therefore should round down.
What the heck is going on here?
The good people over at Tech.Pro have asked me to write a short series of articles for their site on the subject of mistakes I’ve made and seen others make when writing benchmark performance tests of C# code. The series will be pitched at the beginner level.
You can check out part one here. Enjoy!
The intention of this method is to round a double to the nearest integer. If the double is exactly half way between two integers then it rounds to the larger of the two possibilities:[1. For negative numbers, -1.5 should round to -1.0, since -1.0 is larger than -2.0; I do not mean larger in the sense of absolute magnitude. That would be characterized as “midpoint rounding away from zero”.]
static double MyRound(double d)
return Math.Floor(d + 0.5);
Is it correct? Can you find a value for which it does not give the mathematically correct value?[2. HINT: The value I’m thinking of is small.]
UPDATE: The answer is in the comments, so if you don’t want spoilers, don’t read the comments.
Next time on FAIC: The answer, of course.
Today, another of my ongoing series of reruns of my fun-for-Friday non-computer posts. Here’s one from the dot-com recovery of 2004.
The economy must be picking up — I’m getting cold calls from recruiters again for the first time in about four years. Today was the second – and third – this month.
However, apparently some of them are just a wee bit disorganized. I just had the following conversations:
Me: Hi, this is Eric.
Her: Hi, this is Barbara[1. I learned later from some of my fellow Microsoftie bloggers that it appeared that Barbara was calling everyone at Microsoft with an MSDN blog. She must have been repeatedly calling the switchboard and asking to speak with each.] at XYZ Recruiters. How are you today?