Recent Articles

Jun 2024

Broken Loop

by in CodeSOD on

Kyle sends us a puzzler of bad code today. It appears in a "JSP-like" codebase- which Kyle provides no futher details on, but certainly hints at a serious WTF underpinning this code.

boolean loop = true;
while (loop) {
    // fake loop to break out of
    loop = false;

Gonna Need an Extension

by in CodeSOD on

Ever since the DOS days, determining file type based on the three letter extension in its filename has been a common practice. I'd argue that it's not a good practice, but it's become so standard that it's hard to avoid. It's so common that pretty much any language in wide use has some sort of "get extension" method. C# is no exception.

Of course, having a convenient and commonly used helper method is no barrier to writing it yourself, and Andrew found this code in their application, which is meant to extract "png", or "jpg" as the extension.

Terminated Nulls

by in CodeSOD on

When you get into the world of proprietary filesystems, things can get real weird. There are many a filesystem that doesn't support directories, still in use today. Or filesystems which only allocated chunks in multi-megabyte blocks, which means you end up wasting a lot of space if you have small files. Or filesystems where the largest file size is itself a handful of megabytes.

Dan was working on one such filesystem where, when you opened a file for writing, you could specify how many "fixed records" it needed to support. So, for example, if you wanted to open a file for writing, in binary mode, you might do this: open(pathToFile, "f4096wb"): support 4096 records, and open it for writing.

A Mid Query

by in CodeSOD on

Many years ago, Tom supported a VB6 application. It was about 750,000 lines of code, split across far too many files, with no real organization to it. While the code was bad and awful, the organization problem was a universal issue for the application. It even infested the database.

This is some VB6 code for querying that database:

Just a Taste

by in Error'd on

I'm fresh out of snark this week, so I'm relying on the rest of you to carry the load for me. Tote that barge, etc.

First up is a timely comment from an anonymous reader: "Even Kronos admits their software is a pain."

Time for Oracle

by in CodeSOD on

Many a time, we've seen a program reach out into the database for date times. It's annoying to see, but not entirely stupid- if you can't rely on your web servers having synchronized clocks, the centralized database may very well be the only place you can get a reliable date/time value from. This ends up meaning you get a lot of date formatting happening in the database, but again- if it's the only reliable clock, you can't do better.

Unless you aren't even looking at a clock. Mendel sends us this C#:

Maximizing Code Quality

by in CodeSOD on

One of the nice things about Git is that it makes it very easy for us to learn the steps that went into a WTF. It doesn't mean it explains the WTF, as many are just inexplicable, but it's at least something.

Like this example, from Aoife.

I saw the Vorzeichen

by in CodeSOD on

Chilly inherited a VB .Net application which generates an "IDoc" file which is used to share data with SAP. That's TRWTF, but the code has some fun moments:

If ldCashOut < 0 Then 'CashOut
    loE2WPB06002.vorzeichen = " "
    loE2WPB06002.vorzeichen = " "
End If
If liTRANSTYPE = 2 Then 'Refund is always Positive
    loE2WPB06002.vorzeichen = "+"
End If

loE2WPB06002.summe = Math.Abs(ldCashOut).ToString     'CashOut  
loE2WPB06002.zahlart = "PTCS"                           'CashOut
loE2WPB06002.vorzeichen = "-"                           'CashOut

A Type of Alias

by in CodeSOD on

Joe inherited some C code that left him scratching his head.

It doesn't start too badly: