Recent Articles

Oct 2025

A Basic Mistake

by in CodeSOD on

Way back in 1964, people were starting to recgonize that computers were going to have a large impact on the world. There was not, at the time, very much prepackaged software, which meant if you were going to use a computer to do work, you were likely going to have to write your own programs. The tools to do that weren't friendly to non-mathematicians.

Thus, in 1964, was BASIC created, a language derived from experiments with languages like DOPE (The Dartmouth Oversimplified Programming Experiment). The goal was to be something easy, something that anyone could use.


A Truly Bad Comparison

by in CodeSOD on

For C programmers of a certain age (antique), booleans represent a frustrating challenge. But with the addition of stdbool.h, we exited the world of needing to work hard to interact with boolean values. While some gotchas are still in there, your boolean code has the opportunity to be simple.

Mark's predecessor saw how simple it made things, and decided that wouldn't do. So that person went and wrote their own special way of comparing boolean values. It starts with an enum:


A Government Data Center

by in Feature Articles on

Back in the antediluvian times, when I was in college, people still used floppy disks to work on their papers. This was a pretty untenable arrangement, because floppy disks lost data all the time, and few students had the wherewithal to make multiple copies. Half my time spent working helldesk was breaking out Norton Diskutils to try and rescue people's term papers. To avoid this, the IT department offered network shares where students could store documents. The network share was backed up, tracked versions, and could be accessed from any computer on campus, including the VAX system (in fact, it was stored on the VAX).

I bring this up because we have known for quite some time that companies and governments need to store documents in centrally accessible locations so that you're not reliant on end users correctly managing their files. And if you are a national government, you have to make a choice: either you contract out to a private sector company, or you do it yourself.


It's Daniel Time Again!

by in Error'd on

It's been several years now that our reliable contributor Daniel D. has been sending us the same gripe time after time. We get it, really we do. It irks us too, but it is astounding just how many times he's been able to find this!
With no further ado, here is Daniel's pet peeve. See if you can figure out what it is.

640 kB 40 characters must be enough for anybody," right? Daniel bemoaned "US Banks, brokers, financial institutions. You would expect them to put heavy safeguards with stronger the password the better, right? But then you find out they require just 8 to 40 and not a bit more."


This Is Really Empty

by in CodeSOD on

Konrad was trying to understand how an input form worked, and found this validation function.

function IsReallyEmpty($subject)
{
        $trimmed = trim(preg_replace("/&.*;/", "", $subject));
        return strlen($trimmed) != 0;
}

Forward Not Found

by in CodeSOD on

Anthony found this solution to handling 404 errors which um… probably shouldn't have been found.

function show_404($page = '') {
        $uri = $_SERVER['REQUEST_URI'];
        error_log("Caught 404: $uri");
        $redirect_url = "";
       
        switch($uri){
                case "/SOMEURL":
                        $redirect_url="http://www.SOMEWEBSITE.com/SOMEURL";
                        break;
                case "/SOMEOTHERURL":
                        $redirect_url="http://www.SOMEWEBSITE.com/SOMEOTHERURL";
                        break;
                case "/YETANOTHERURL":
                        $redirect_url="http://www.SOMEWEBSITE.com/YETANOTHERURL";
                        break;
                // ... THERE ARE 300 of these ...
                case "/MOREURLS":
                        $redirect_url="http://www.SOMEWEBSITE.com/MOREURLS";
                        break;
                case "/EVENMOREURLS":
                        $redirect_url="http://www.SOMEWEBSITE.com/EVENMOREURLS";
                        break;
        }

        if ($redirect_url){
                Header( "HTTP/1.1 301 Moved Permanently" );
                Header( "Location: $redirect_url" );
        } else {
                parent::show_404($page);
        }
}

A Percentage of Refactoring

by in CodeSOD on

Joseph was doing a refactoring effort, merging some duplicated functions into one, cleaning up unused Java code that really should have been deleted ages ago, and so on. But buried in that pile of code that needed cleaning up, Joseph found this little bit of code, to validate that an input was a percentage.

@Override
public Integer validatePercent(final String perc, final int currentPerc){
    char[] percProc= perc.toCharArray();
    char[] newPerc = new char[perc.length()];
    int percent=0;
    int y=0;
    if(percProc.length>4){
        return -1;
    }
    for(int x=0;x<percProc.length;x++){
        if(Character.isDigit(percProc[x])){
            newPerc[y]=percProc[x];
            y++;
        }
    }
    if(y==0){
        return -1;
    }
    
    String strPerc=(new String(newPerc));
    strPerc=strPerc.trim();
    if(strPerc.length()!=0){
        percent=Integer.parseInt(strPerc);
        if(percent<0){
            return -1;
        }else if(percent>100){
            return -1;
        }else if(Integer.parseInt(strPerc)==currentPerc){
            return -1;
        }else{
            return Integer.parseInt(strPerc);
        }
    }else{
        return-1;
    }
}

The Batch Managing Batch File

by in Representative Line on

Carl was debugging a job management script. The first thing that caught his attention was that the script was called file.bat. They were running on Linux.

The second thing he noticed, was that the script was designed to manage up to 999 jobs, and needed to simply roll job count over once it exceeded 999- that is to say, job 1 comes after job 999.


Domino Theory

by in Error'd on

Cool cat Adam R. commented "I've been getting a bunch of messages from null in my WhatsApp hockey group."


A Date Next Month

by in Representative Line on

We all know the perils of bad date handling, and Claus was handed an annoying down bug in some date handling.

The end users of Claus's application do a lot of work in January. It's the busiest time of the year for them. Late last year, one of the veteran users raised a warning: "Things stop working right in January, and it creates a lot of problems."


A Refreshing Change

by in Feature Articles on

Dear Third-Party API Support,

You're probably wondering how and why your authorization server has been getting hammered every single day for more than 4 years. It was me. It was us—the company I work for, I mean. Let me explain.


The Bob Procedure

by in CodeSOD on

Joe recently worked on a financial system for processing loans. Like many such applications, it started its life many, many years ago. It began as an Oracle Forms application in the 90s. By the late 2000s, Oracle was trying to push people away from forms into their newer tools, like Oracle ApEx (Application Express), but this had the result of pushing people out of Oracle's ecosystem and onto their own web stacks.

The application Joe was working on was exactly that. Now, no one was going to migrate off of an Oracle database, especially because 90% of their business logic was wired together out of PL/SQL packages. But they did start using Java for developing their UI, and then at some other point, started using Liquibase for helping them maintain and manage their schema.


The File Transfer

by in CodeSOD on

SQL Server Integration Services is Microsoft's ETL tool. It provides a drag-and-drop interface for describing data flows from sources to sinks, complete with transformations and all sorts of other operations, and is useful for migrating data between databases, linking legacy mainframes into modern databases, or doing what most people seem to need: migrating data into Excel spreadsheets.

It's essentially a full-fledged scripting environment, with a focus on data-oriented operations. The various nodes you can drag-and-drop in are database connections, queries, transformations, file system operations, calls to stored procedures, and so on. It even lets you run .NET code inside of SSIS.


Yes We Have No Bananas

by in Error'd on

There is fire sale on "Test In Production" incidents this week. (Ok, truth is that some of them are a little crusty and stale so we just mark them way down and push them all out at a loss). To be completely fair, testing in production is vitally important. If you didn't do that, the only way you'd know if something is broken is when one of your paying customers finds out. I call that testing in production the expensive way. The only WTFy thing about these is that when you test in production, your customers shouldn't stumble across the messes.

"We don't often test, but when we do it's always in production" snarked Brad W. unfairly. "My phone gave its default alert noise mixed with... some sound that made it seem like the phone was damaged. This was the alert that appeared. "


A JSON Serializer

by in CodeSOD on

Carol sends us today's nasty bit of code. It does the thing you should never do: serializes by string munging.

public string ToJSON()
{
    double unixTimestamp = ConvertToMillisecondsSinceEpoch(time);
    string JSONString = "{\"type\":\"" + type + "\",\"data\":{";
    foreach (string key in dataDict.Keys)
    {
        string value = dataDict[key].ToString();

        string valueJSONString;
        double valueNumber;
        bool valueBool;

        if (value.Length > 2 && value[0].Equals('(') && value[value.Length - 1].Equals(')')) //tuples
        {
            char[] charArray = value.ToCharArray();
            charArray[0] = '[';
            charArray[charArray.Length - 1] = ']';
            if (charArray[charArray.Length - 2].Equals(','))
                charArray[charArray.Length - 2] = ' ';
            valueJSONString = new string(charArray);
        }
        else if ((value.Length > 1 && value[0].Equals('{') && value[value.Length - 1].Equals('}')) ||
                    (double.TryParse(value, out valueNumber))) //embedded json or numbers
        {
            valueJSONString = value;
        }
        else if (bool.TryParse(value, out valueBool)) //bools
        {
            valueJSONString = value.ToLower();
        }
        else //everything else is a string
        {
            valueJSONString = "\"" + value + "\"";
        }
        JSONString = JSONString + "\"" + key + "\":" + valueJSONString + ",";
    }
    if (dataDict.Count > 0) JSONString = JSONString.Substring(0, JSONString.Length - 1);
    JSONString = JSONString + "},\"time\":" + unixTimestamp.ToString() + "}";
    return JSONString;
}

A Unique Mistake

by in Feature Articles on

Henrik spent too many hours, staring at the bug, trying to understand why the 3rd party service they were interacting with wasn't behaving the way he expected. Henrik would send updates, and then try and read back the results, and the changes didn't happen. Except sometimes they did. Reads would be inconsistent. It'd work fine for weeks, and then suddenly things would go off the rails, showing values that no one from Henrik's company had put in the database.

The vendor said, "This is a problem on your side, clearly." Henrik disagreed.


Listing Off the Problems

by in Representative Line on

Today, Mike sends us a Java Representative Line that is, well, very representative. The line itself isn't inherently a WTF, but it points to WTFs behind it. It's an omen of WTFs, a harbinger.

ArrayList[] data = new ArrayList[dataList.size()];

A Monthly Addition

by in CodeSOD on

In the ancient times of the late 90s, Bert worked for a software solutions company. It was the kind of company that other companies hired to do software for them, releasing custom applications for each client. Well, "each" client implies more than one client, but in this company's case, they only had one reliable client.

One day, the client said, "Hey, we have an application we built to handle scheduling helpdesk workers. Can you take a look at it and fix some problems we've got?" Bert's employer said, "Sure, no problem."


Neither Here nor There

by in Error'd on

... or maybe I should have said both here and there?

The Beast in Black has an equivocal fuel system. "Apparently, the propane level in my storage tank just went quantum, and even the act of observing the level has not collapsed the superposition of more propane and less propane. I KNEW that the Copenhagen Interpretation couldn't be objectively correct."


Tic Tac Whoa

by in Tales from the Interview on

Usually, when we have a "Tales from the Interview" we're focused on bad interviewing practices. Today, we're mixing up a "Tales" with a CodeSOD.

Today's Anonymous submitter does tech screens at their company. Like most companies do, they give the candidate a simple toy problem, and ask them to solve it. The goal here is not to get the greatest code, but as our submitter puts it, "weed out the jokers".


Property Flippers

by in CodeSOD on

Kleyguerth was having a hard time tracking down a bug. A _hasPicked flag was "magically" toggling itself to on. It was a bug introduced in a recent commit, but the commit in question was thousands of lines, and had the helpful comment "Fixed some stuff during the tests".

In several places, the TypeScript code checks a property like so: