Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

Jan 2026

A Sudden Tern

by in CodeSOD on

Matthias sends us what he calls the "tern of the century". Which, before I share it with you: bad news, it's just a regular bad ternary. But it remains bad in interesting ways, so it's definitely worth talking about. But let's not oversell it.

private static String getOrderTypeCode(CreateOrderRequest order) {
  return !StringUtils.isBlank(order.getOrderParams().getReceivingCompanyFoo()) && ORDR_TP_DQQ_FOO.equals(order.getOrderParams().getOrderType()) ? ORDR_TP_DQQ_BAR_CDE : order.GetOrderParams().getOrderType().getOrderTypeCode();
}

Going Through Time

by in CodeSOD on

Philipp H was going through some log files generated by their CI job to try and measure how long certain steps in the process took. He took the obvious path of writing code to read the logfiles, parse out the timestamps, and then take the difference between them.

Everything worked fine, until for certain steps, a negative timestamp was reported:


A Pirate's Confession

by in CodeSOD on

Today we have a true confession from Carl W. It has the benefit of being in R, which means that at a glance, I just assume "eh, looks fine to me." I guess I'm turning into Jimbo.

But let's dig into it. Carl's first snippet is this:


The Review

by in CodeSOD on

Frequent contributor Argle Bargle (recently, or even in last week's Errord) works with a programmer called "Jimbo". Jimbo is a solid co-worker and a good programmer. He has more tenure at the company than Argle, which means Jimbo is who Argle goes to when he has questions.

Recently, Argle worked his way through a rather complicated bit of code. It involved passing data between two different languages inside of a real-time system. Much of its functionality was opaque and complicated, so Argle wrote literal paragraphs of documentation explaining what the code did, how to invoke it, what the gotchas might be, and how to avoid them.


No Yes

by in CodeSOD on

It's common to see code in the form of if (false == true). We get a fair bit of it in our inbox, and we generally don't post it often, because, well, it's usually just a sign that someone generated the code. There's a WTF in that, somewhere, but there's not much to say about the code, beyond, "Don't generate code, pass data from backend to frontend instead."

But Nicholas sends us one that shows a little more of interest in it.


The Utils

by in CodeSOD on

We know 2026 is not a leap year. But how do we know that? We need to call some function to find out.

Steve sends us a bit of representative code; on it's own, it's not so bad, but with the broader context, it's horrifying: