From the Annals of Dubious Achievement
July 13th, 2009

It is I who wrote RichardIsAFuckingIdiotControl, voted the “best comment in source code … ever encountered” in this StackOverflow question. I didn’t submit it, nor do I know the person that did. (I came across it on reddit, or something. I don’t have the will or personal bandwidth to participate in something like StackOverflow.) This happened at a former employer.

I am not sure that I am proud of this. Actually I’m pretty sure that I’m not proud of it. But I’ll explain what the deal was for the record anyway. I am also not sure that this deserves the “accolades” that it received. After all it’s not technically a comment (although it contains some doozies) and I would never have chosen pure vitriol over, say, something from Ritchie’s Odd Comments and Strange Doings in Unix.

Obviously what sets this apart from other snippets in the genre is the over-the-top hatred of a very specific colleague. So let me tell you a little about Richard.

First, his name wasn’t Richard. Whoever submitted the sample was wise enough to change that (thanks, guy). I didn’t even use his given name in the original source, although it was a moniker that most people would have understood. “Richard” was no longer employed by the company when I wrote this. He had recently been fired for repeatedly showing up in the early to mid-afternoon drunk and coked out of his mind (I guess nobody told him that we real programmers show up on time and drink at our desks).

Richard was a recent college grad with roughly a 1.8 GPA from a decent-but-not-prestigious CS program. Miraculously (if you’re Richard), someone decided he was a “cultural fit” and therefore deserved $70K per year. For readers who have only ever been exposed to polite society, it is important to note that this is standard practice in the financial industry and is considered “normal.” Around this time, I had gotten a little bent out of shape about hiring for various reasons that I won’t go into, and I was the asshole. Go figure.

Personally, there is only one word that describes the kid. That word is broseph. If I were to call him a violent, drug-addled menace, it would not be hyperbole. Let me say it again, “cultural fit.”

After Richard’s exit, I had to take over his code. I wound up rewriting almost all of it from scratch, and this class was serving as a blast shield around the volatile remains of what I could salvage. Honestly, at this point I was bored to tears, and a lot of what I did was probably total crap. If there’s any justice, right now someone’s writing a profanity-laden class with my name all over it.

But anyway, let’s go over the code. I’ll add some color, where I can remember what was going on.

// The main problem is the BindCompany() method,
// which he hoped would be able to do everything. I hope he dies.

I am firmly opposed to the death penalty, but if a piano fell on his head I would be sincerely happy. (And again, for some reason I’m the asshole.)

public void BindCompany(int companyId) { }

// snip

private void MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity()
{
    // Make sure nobody is actually using that fucking bindcompany method
    MethodInfo m = this.GetType()
        .GetMethod("BindCompany",
                   BindingFlags.DeclaredOnly
                   | BindingFlags.Instance
                   | BindingFlags.Public
                   | BindingFlags.NonPublic);
    if (m != null)
    {
        throw new RichardIsAFuckingIdiotException(
          "No!! Don't use the fucking BindCompany method!!!");
    }
    // P.S. this method is a joke ... the rest of the class is
    // fucking serious
}

There was some deeply-entrenched reason why I could not change the definition of the BindCompany method. It had to be there, but the code paths that called it were all fundamentally flawed, or something like that. I decided to be funny and use reflection to raise an exception if anyone happened to redefine with an implementation of it in a derived class.

/// <summary>
/// This returns true if this control is supposed to be doing anything
/// at all for this request. Richard thought it was a good idea to load
/// the entire website during every request and have things turn themselves
/// off. He also thought bandanas and aviator sunglasses were "fuckin'
/// gnarly, dude."
/// </summary>
protected bool IsThisTheRightPageImNotSureBecauseRichardIsDumb()
{
    return Request.QueryString["Section"] == this.MenuItemKey;
}

One of the really crazy things about this application was that for every web request, it would actually load several hundred control classes and call methods on them. Maybe two or three of these would actually be necessary. They would all determine (based on the URL, I think) if they were supposed to be drawing anything. It would have been much easier to, god I don’t know, just call the methods that were necessary to draw each page. I still have nightmares about this ridiculous contraption every now and then.

I guess the StackOverflow snippet doesn’t capture this, but the best thing about Richard’s code was that he loved property getters and setters. No, wait, that’s not quite right. Lots of people love getters and setters, but Richard seemed to be in love with getters and setters. So much so that about 70% of his logic took place in them. More than once I deleted code that looked like this:

foo.x = foo.x;

Only to break entire pages, because the side effects of that assignment were doing everything. Anyway, I hope you can all see where I was coming from now.


And We're Back
July 8th, 2009

So, I have finally fixed this stupid site. I spent years devising plans for rewriting it in lisp, or something, then one day read this essay about perfectionism and decided I was being completely ridiculous. Yes, that is my dog in the header, thank you for asking.

Some would have balked at the prospect of hand editing years of predominantly embarrassing posts, but I soldiered on through good times and bad. I am still messing with the layout and I haven’t even looked at the damn thing in Internet Explorer yet. (If you have IE—I don’t at home—let me know if something is really messed up.)

Evidently, once upon a time I had a career writing a lot of code for various Microsoft platforms. I feel like that part of my life needs to remain there for posterity, even though I am very happily participating in the open source, OMG-scale web world these days.

If I leave those posts there, perhaps someday someone can explain them to me. Very few of them make any sense to me now. I do remember fielding the e-mail from the ignoramus I-banker that prompted me to write Significant Digits for the Inummerate. With a little luck, his life is now ruined forever.

I thought I would miss debugging obscure threading issues, and rooting through core dumps, and staring at disassembly, but I was wrong. I have come to appreciate the sublime beauty of fork, the challenge of writing code for epic scale, having the damn source code, and solving problems that matter to people that are not evil mutants. I haven’t hand-edited XML in two years. Life is beautiful. Hopefully with the whole “blog” issue out of the way I will be able to think of something interesting to talk about.


PHP FAIL
October 6th, 2008

The explanation for maybe 70% of the pages on the internet that say,

Well I don’t know what the hell just happened but maybe you should delete your cookies.

can be found here. Specifically,

The setcookie function will silently change the ‘’ cookie value to ‘deleted’ and override your expiry time to time() - 1 year.

Now in percentage terms, the number of people that have a local date that is incorrect by more than one year is probably very small. However the law of enormous numbers implies that at least of few such people will be using your site if you are successful, more or less depending on your usage demographics. What is the result? Well, those people are sending you “deleted” as a cookie value and your naively-written script probably has no idea what to do with it. Then your script tries to delete the cookie if it doesn’t know how to handle it, but hey we’ve been here already, and everybody frowns and scratches their heads for a bit before giving up and writing the “what the hell” error page.

The preventative measure I would suggest in situations like these is writing relatively low-level tests to hit your pages and confirm that your application is being a good HTTP citizen. Even if you have to hack around PHP’s hacks to accomplish this.