Saturday, October 20, 2018

Take a Chance

An image of the Earth as taken from the north pole (approximately). It's shaded so that the California timezone is at meridian. Around the Earth is a ring of green circles. Hanging just above California is a red circle.

It was late and Samantha was at work, again.

Her phone buzzed, faintly vibrating against the desk and dancing in her peripheral vision. It was probably her husband, texting to find out when she would be done for the fiftieth time.

She couldn't be distracted. It was an intermittent problem and she was finally able to reproduce it. She was on the scent.

One more Ctrl+Click and she'd find that damn NullReferenceException.

What she saw was repellant. She recoiled both mentally and physically.

"Fucking Kramer," she murmured. "What the fuck is this?"

Sam looked around to make sure nobody had overheard her disparage a coworker. At InterIntraCo, one could do no wrong except in making another feel uncomfortable.

She was safe.

The code was bizarre; a long, winding stretch of nonsense inaugurated by the following abstruse comment...

// Fix timezone bug from Sunday

What "timezone bug"? Which "Sunday"?

Kramer was the worst programmer on the team. He showed up at ten thirty. He left at five. His code made no sense and nobody could ever seem to draw any connection between what he did and a requirement.

His code was so bad that nobody minded his short hours. Most people on his team wished he would leave earlier.

This time, he really stepped in it. There was a proxy class for a data store, which was responsible for storing and retrieving audience-member data for IntraInterCo's line of online marketing products.

Before Kramer's "fix", there was this method...

public Audience GetMember(string token) {
  string document = store.FindById(token);
  return JsonCodec.FromJson<Audience>(document);
}

After Kramer's "fix", this is how the code read...

public Audience GetMember(string token) {
  string document = store.FindById(token);
  if (document.LastUse.TimeOfDay > TimeSpan.FromHours(23) &&
    document.LastUse.TimeOfday < TimeSpan.FromHours(1)) {
    document.Hardware = null;
  }
  return JsonCodec.FromJson<Audience>(document);
}

Samantha slammed her clenched fist on the desk and repeated her lament. "What the fuck?!?"

The entire system was dependent on an Audience having its Hardware property be populated. Nobody checked that Hardware wasn't null because, until then, it never was.

She ran her fingers through her long, dishwater blonde hair.

"Fuck that guy," she muttered.

Click. Hold. Drag. Delete...

The cure for all Kramer's code, she mused.

A few seconds later, a green bar told her that it was safe to check in her code. She did so with one hand while grabbing her phone with the other.

On the elevator to the parking level, she texted Jack to let him know she was on her way.

Twenty minutes later, she was home and asleep. It stands to reason, she didn't notice the phone buzzing in her purse, quietly letting her know she broke the build.

On Monday, when she arrived for work, she found out what happened.

None of the unit tests failed when she made her change but an integration test was no longer passing. She always got to the office last, so everyone else had been dealing with it all morning.

Sam's cheeks flushed red.

"All the tests passed," she said.

Her coworker, Fred, laughed and said "Don't worry. We've already figured out what happened."

'What was it?"

"Kramer."

Samantha shrugged her request for more.

"Five weeks ago, he wrote some weird code. Here", said Fred. "Let me show you."

The code was in a distant part of the system that used an Audience object...

public int GetIdentificationConfidence(Audience audience) {
  var confidence = 0;

  // snipped

  if (audience.Hardware != null) {
    if (audience.Hardware.Type == HardwareType.Mobile)
      confidence += 10;

    if (audience.LastUse.TimeOfDay - DateTime.Now.TimeOfDay <
      TimeSpan.FromHours(-1))
      confidence -= 25;
  }

  // snipped

  return confidence;
}

"I see," said Samantha. "I'm assuming nobody knows why he wrote that, least of all him. So what was the 'Timezone bug from Thursday'?"

"When he checked that in, everything was fine. Most of the time, this doesn't get hit. The Sunday before last, one of the integration tests hit that code just wrong. The setup stuff happened right before midnight and the assertion stuff right after."

A grim smirk crept over Samantha's face. "...and it just happened to be one of the confidence score tests."

"Yeah... So his 'fix' was basically to make sure his code doesn't run in the 11:30 nightly. You took it out and just happened to get hit by the same timing issue."

"So how did you fix it?" asked Samantha.

Fred chuckled and said, "The same way you fixed the null reference exception, on Friday."

Samantha jerked a little nod of acknowledgment.

They both made their pleasantries and began to drift toward their respective desks. After a few steps, something occurred to Sam.

"Wait a sec," she almost shouted. "Why did he call it a 'timezone bug'?"

Fred laughed and answered, "Oh right! That's the best part. What happened, two Sundays ago?"

Samantha shook her head.

"Daylight savings time," said Fred. "Spring forward." He raised his eyebrows as he added "Kramer."

Samantha snorted and replied "Kramer."

(continued here)