There’s plenty of bad code that makes you ask, “what were they thinking?” There’s a whole bunch of code we get, however, that doesn’t even raise that question- the programmer responsible simply wasn’t thinking. Today, let’s examine a few “programmer brain-farts”. We turn our attention first, to Jim C.

While reviewing some unit tests, he found this line:

if (!succeeded) {
    SmartAssert::IsTrue(succeeded, messageStr);
}

This, obviously, confirms that succeeded is false, and the asserts that succeeded shouldn’t be false. Perhaps not so smart an assert. Jim ran blame to find the party responsible, but as it turned out- he had written this code six months earlier.

Oh, to live in a world where we are the only source of our own pain. Jason is not so lucky. It was the eve of a major release, and there was a bug. Certain date values were being miscalculated. What could possibly be the cause?

Well, after a frantic investigation, he found a fellow developer had done this:

SystemTime startTime = getCurrentSystemTime().subtractSeconds(TimeUnit.HOURS.toMillis(1));

What is supposed to be calculating out one hour prior was actually calculating out 1000 times that much. While they discovered this bug right before a release, the code had been in production for months.

Meanwhile, Dave was hunting through some code, trying to understand some of the output. Eventually, he traced the problem to a function called generateUUID.

public static String generateGUID(AuditLog auditLog) {
  String guid = UUID.randomUUID().toString();
  return (guid + auditLog.getContextName() + auditLog.getRequestStart().getTime());
}

This was simply a case of a very poorly named function. At no point in its history had it ever actually generated a UUID, and had always returned some variation on this string concatenated version.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!