Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
No kidding, I was just walking down a hallway in my building when I overhead the following quite loud conversational fragment through an open doorway:
Angry woman's voice: "Why are you in the ladies room?! You are the third man to... oh no."
Like Hobbes, it's the moment of dawning comprehension that I live for - the exact moment when she realized that she, not everyone else, was in the wrong room was readily apparent. (One wonders what the first two gentlemen did, since clearly they did not successfully disabuse the lady of her error.) Since the building across the courtyard from mine has a mirror-imaged layout, this is a very easy mistake to make if you are visiting from the other building.
I contrast that moment of dawning comprehension with Dr. Crusher's similar moment in that memorable 1990 episode of Star Trek: The Next Generation when she realizes that she's not crazy, it's the entire universe that is wrong. When faced with an absurd and unexpected situation - the gradual disappearance of first the crew and then the entire universe - she at least considers that she's the crazy one.
Unlike most people, I encounter compiler and library bugs all day long in my job, though mostly ones that I caused in the first place. (Sorry!) But even still, when I am writing "normal" code (rather than test cases designed to break the compiler or regress previous bugs), I try to ensure that my attitude upon encountering an unexpected situation is that I'm the crazy one. Usually it's my code that is wrong, or my misunderstanding the output, rather than a compiler or library bug.
As the authors of "The Pragmatic Programmer" point out in their third chapter, "select() isn't broken" - if you are writing perfectly normal code then odds are good you are not the first person to discover what should be an obvious problem in a well-tested product. If you think you've found a bug in the math library, maybe you have. Or maybe you've actually passed radians to a method that takes degrees, or forgotten to take floating point rounding error into account, or some other such thing. The more obvious the problem, the more likely it is that you're the crazy one. If the code doesn't compile and you think it should, it could be a bug in the compiler. But read the error message carefully; it is probably telling you what is wrong with the code.
If you think you've found a C# compiler bug, please, by all means bring it to our attention; post it on Connect, or have the community take a gander at it via StackOverflow or one of the Microsoft forums, and if you want, send me a link to the problem. (Please don't use the "contact" link to send me source code directly; the hostile-email sterilization code that filters that text is very aggressive about stripping out things that look potentially harmful. It makes code almost illegible.) There certainly are bugs in the compiler and the more we get good information on, the better. Including a small-but-complete program that reproduces the problem and the version number of the compiler you're using is a big help. But first, do stop and take a good hard look at the code and think about whether it is more likely to be a problem with the code or a problem with the compiler. Don't be one of those people who sends me angry, profane emails about a problem that you caused yourself; that's just embarrassing.
Ha ha! I laugh because I've was the exact same situation as that unfortunate woman when I was about 14 years old. In my case, the detective work necessary to figure out why there were no urinals in this particular "men's room" took just a few seconds longer than getting started. Once I had my moment dawning comprehension, I had a difficult decision to make...stop and make a walk of shame to the actual men's room or just finish out. To this day, I wonder what I would have done if a woman had walked in while I was there.
On a more on topic note, it's nice to know that you also have moments where the system works correctly albeit contrary to your expectations. The systems I work on are significantly less complex than a compiler, but I can recall many times where the system has performed non-intuitive action and it takes a few of us a few minutes to realize its not a bug.
I find that this is exactly the mental block that some people have when fixing bugs. They trust some part of the code and not another part and can't make the mental leap that the problem is in the trustworthy part. Once they've been burned this way they can actually become paranoid and begin distrust crazy things like addition when other suspects should be considered first. This is the art of debugging: holding everything you think to be true with some doubt without driving yourself crazy.
And this is precisely why I've started to insist first that the person claiming there's a bug justify his code. Once he demonstrates that he's using it correctly to do something reasonably within scope, and that what he's doing actually makes sense for what it is he's trying to solve, we can talk about whether there's a bug.
I must say, the sentence about "the hostile-email sterilization code" made more sense when I misread it as "the hostile email-sterilization code". Why can't they get that right?
When my program does something wrong, the mistake is nearly always mine, but there is one exception: stackoverflow.com/.../delegate-system-action-does-not-take-0-arguments-is-this-a-c-compiler-bug :)
I always assumed that the more experienced you became, the more likely you were to blame yourself when stuff does not work right.
I also hate dawning comprehension, as when I slowly realised that the reason the urinals at the sports stadium were strangly high... and wide... and flat... was they were in fact the basins. Not my best moment ever.
A man on his way home receives a call from his wife. "Be careful honey, the news is showing a car going the wrong way on the interstate!" "One car?" he replies. "Hell, there's dozens of them!"
I find that using a "Cardboard programmer" to explain the nature of the bug usually solves the "problem". PS if anybody out there has an unwanted life sized Peter Norton cardboard cutout in good condition, give me a shout.
Am I the only one that wants to see the particular email that spawned this post? Redact some personal information and stick it up!
I've been seeing a number of "select isn't broken" posts on StackOverflow lately. And I've just been meaning to write this sort of thing for a while. Overhearing that unintentional situation comedy moment yesterday provided sufficient activation energy. -- Eric
@Nat, "I also hate dawning comprehension, as when I slowly realised that the reason the urinals at the sports stadium were strangly high... and wide... and flat... was they were in fact the basins. Not my best moment ever."
This seems to be a common problem with fancy, designer basins. The Dome theatre in Brighton, UK has fancy basins that are basically long, low stainless-steel troughs. I've seen several men walk into there when it's busy, take a pee and as they are doing so, slowly realising that they are just missing the soap dispensers, and yes, they are peeing where the other guys are just about to wash their hands. Amusing.
Maybe it's just Brighton, but many girls tend to use the men's toilets when there are big queues at theirs. I was in one the other day and a girl just came and squatted on the men's urinal with a bunch of guys standing next to her, and another woman was doing her makeup in the mirror completely nonchalantly. Gender separation in toilets is a recent historical phenomenon so maybe it will just disappear.
@Paddy B: Eric did recently reference "select isn't broken" in his reply to this question on StackOverflow:
What I find interesting is Eric's comment on the answer: "I assure you that there is a bug in the library. It's just that this isn't it."
You don't happen to know the name of that star trek episode, do you?
You'll note that I put a convenient "hyperlink" to the Star Trek wiki. If you click on that link, you'll get information about the episode. -- Eric
I always start out by assuming that the problem is with me and not the compiler. It's usually a safe assumption, except for that one time when I actually did find a bug in the C# 4 compiler. The BadImageFormatException suggested very strange was afoot :). Thanks again for checking it out for me, and for your detailed explanation (it was the generic virtual iterator bug).
@Erik: "Remember Me" (Star Trek: TNG, Episode 4x05)
My experience tends to be "you're not the first person to try this, but the universe is indeed broken".
I'll struggle with something for a little while and then STFW and find that a bunch of other people have run into exactly the same bug, sometimes years ago, with no fix in sight. :-(