I used to work with this guy, let's call him Chronos, who was a classic cowboy programmer. He coded everything like his hair was on fire, the code he wrote looked like crap and was full of bugs. Aside from that he was actually a nice guy and worked hard. I enjoyed my social interactions with him, but I didn't enjoy fixing the bugs he laid down. I thought I'd share an example of the way he worked on features.

We were working on a crypto currency exchange and management wanted us to run a trading game in the company to identify bugs and performance problems. So for three weeks everyone in the company could create an account and paper trade Bitcoin for USD back and forth. We had a mechanism to make the price on our exchange track the price on Coinbase.

Management then had a thought "Wait a minute, if everyone has access to this paper trading game, they'll be trading instead of doing work. Let's make sure the exchange is only available from 12 PM to 2PM and 6 PM to 9 AM". Chronos understood the requirement and wrote some code similar to this:

fun isOpen(time: ZonedDateTime): Boolean {
    val hourOfDay = time.hour
    return (hourOfDay >= 12 && hourOfDay <= 14) || hourOfDay <= 9 || hourOfDay >= 16
}

I thought that was pretty reasonable, he hardcoded the opening hours, but since they only apply for this three week period it seemed okay to me. Unfortunately management had finished reorganising the furniture in their offices and decided to do some more thinking. "Wait a minute! The exchange should be available 24 hours a day on the weekend." Chronos was given the task. You could implement such a feature like this:

fun isOpen(time: ZonedDateTime): Boolean {
    val dayOfWeek = time.dayOfWeek

    if (dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) {
        return true
    }

    val hourOfDay = time.hour
    return (hourOfDay >= 12 && hourOfDay <= 14) || hourOfDay <= 9 || hourOfDay >= 16
}

It's getting a bit more complicated, but it should all be deleted at the end of the trading game. This is how Chronos solved the problem

fun isOpen(time: ZonedDateTime): Boolean {
    if (System.getenv("EXCHANGE_IS_OPEN_OVERRIDE").toBoolean()) {
        return true
    }

    val hourOfDay = time.hour
    return (hourOfDay >= 12 && hourOfDay <= 14) || hourOfDay <= 9 || hourOfDay >= 16
}

He added in an environment variable that forced the exchange to be open when it was set. This added in two manual tasks for him to do every week:

  1. At Friday 6 PM Chronos SSHs onto the server, enables environment variable and then restarts the web server.
  2. On Monday 9 AM Chronos SSHs onto the server, disables the environment variable and then restarts the server.

The complexity of the code is about the same, he's added in an ugly environment variable deep in the code and added about twenty minutes of extra work per week. If I was reviewing the PR I would have probably failed it, or just coded in the weekend check for him. Someone else approved it though so it slipped through. Doesn't seem that bad does it? I kind of didn't care and thought it was crap but not bad enough to throw a hissy fit.

It actually turned out to be worse than I thought. During the trading game we frequently pushed code into production to fix bugs. Every time we pushed into production Chronos's EXCHANGE_IS_OPEN_OVERRIDE variable disappeared. There were three weekends during the trading game and each Saturday at 9 AM the exchange was incorrectly shut because the stupid environment variable wasn't set. Someone would report the bug and Chronos would log onto the box and set it.

The story has a happy ending though, I left the company and no longer have to deal with Chronos's ridiculous code.