Recent Articles

Apr 2023

Boy Howdy

by in Error'd on

A couple of mojibakes and only one really awful pun this week. This editor was in Texas for the week and just can't escape the John Wayne references.

Long-time listener, first-time caller Bruno shared his first submission after 20 years and ran into a bit of a hitch, which we're saving for a special episode. But here's his historic snark: "It's not that often that we see errors in Big Name Games on TDWTF. Well, the lastest heir to the Borderlands series of games is Tiny Tina Wonderland, and it delivers. Of course, it also delivers a way to optimize your inventory, because that's in the Borderlands genes. However, this was an [endgamebold] first: I still kept the legendary, sorry ;-)" Thanks, Bruno!


An Incremental Replacement

by in CodeSOD on

Jon sends us an entire function, but I'm just going start with the comment, after which you'll understand everything bad about this without me explaining further. Don't worry, I will, but the comment says it all:

/**
 * Returns the next ID of a table. This function is a replacement for MySQL's
 * auto-increment so that we don't need it anymore.
 *
 * @param  string  $table The name of the table
 * @param  string  $id    The name of the ID column
 * @return integer
 */

Bubbled to the Top

by in CodeSOD on

What makes code bad? Is it an inherent property of the code itself? Or is it the context in which the code is placed?

For example, let's look at this function, found by Lars.


Dining on Leftovers

by in CodeSOD on

Sometimes, you go up to the fridge, looking for a snack, and see the array of leftovers, and your appetite fails you. You want to eat, you know you have plenty of options that you just need to throw into the microwave, but none of them look appetizing. Leftovers always seem like a better idea when you're busy making them than when you're trying to deal with them after the fact.

Stev's co-worker has left them a large pile of leftovers. This block is representative of all the half-finished leftovers that don't do anything and shouldn't be there, but happily make it much harder to understand the codebase:


Randomly Generated

by in CodeSOD on

There was an era, briefly, where corporations flirted with the idea of replacing their web based UIs with Flash. There were even UI frameworks, like Flex, built to support that kind of migration. Yes, it was a disaster.

But not quite as much of a disaster as this action script code that Daniel found. At some point, someone at Initech decided they needed to implement a random number generator. This is what they came up with:


NaaN

by in Error'd on

NaaN stands for NaN Ain't A Number. But other things most certainly are, even though we don't always think of them as numbers or represent them as decimals. MCMLXVI, for example. Sometimes zero. Maybe even more so 5-i. This week we have some special numbers for you, among other things.

Lonely dog-lover Kevin M. was thrown from joy to despair in barely one second. "Embark found some new relatives for my dog... or not." It's arguably technically true that Embark found a number of new pup kin.


Get Selected

by in CodeSOD on

Matt is supporting an old VB.Net application. This representative line highlights the overall code quality:

If Me.lstRequests.GetSelected(Me.lstRequests.SelectedIndex) = False Then

Providing Authentication

by in CodeSOD on

Paulette's team had built a wrapper method around the C# authentication APIs that acted as a convenience function. Called GetAuthenticationProvider, it accepted two parameters. The first, a string, could be used to look up the provider's type in a lookup table. The second was a boolean, which indicated whether it should be an local authentication provider, or an external provider (e.g., OAuth). At least, that's what the documentation says.

The function would find and/or construct the correct type of provider, and return it. They all shared an interface, so this all should work just fine.


Random Permutation

by in CodeSOD on

Gary inherited some C code. This C code is correct, and does what it is supposed to, which is itself a pretty straightforward problem: create an array of values from 0-N, arranged in a random order.

Now, there are a lot of possible ways to do this, most of which involve swapping cells in the array around. It's quick, efficient, and easy to understand. Which means Gary's co-worker needed to find a better solution.


Projection Your Failures

by in CodeSOD on

Geoinformatics ends up needing to deal with a pretty thorny problem: projecting a sphere onto a 2D coordinate system. There is no single correct way to do this, and depending on many factors, you may need to choose different projections- for maps covering small regions, the curvature of the Earth might have only a minor effect; the curvature is different depending on your latitude; depending on your needs, you might need different projections that prioritize retaining (or discarding) certain relationships between map coordinates.

Given how hard this problem is, people have put a lot of time and effort into solving it with some standards. In this case, the standard is EPSG codes, a registry of reference systems, different values for the shape of the Earth, and different coordinate systems, all granted a unique identifier in the range 1024–32767.


Bon Weekend

by in Error'd on

Jobhunter Quentin G. is finding the current labor market to be very challenging. Says he: "The job sounds cool, but that would be quite a salary cut."


Regular Query String

by in CodeSOD on

Robert H is taking the first steps required to make existing code supportable: writing unit tests. The code in question isn't that old, it was just developed by someone who didn't care about mundane tasks, like testing.

They also didn't care about things like paying attention to web standards, and thus were using the same copy/pasted utility functions they'd been using for a decade.


Self-Documentation

by in CodeSOD on

It's rare to find truly self-documenting code. Adam, however, while hunting down a bug, found some.

Adam was trying to understand exactly where some functionality was coming from in a Java program. The code base had some very long inheritance trees, which was an absolute nightmare for maintenance. The mix of overridden methods and mysterious interfaces and dependencies from the lowest levels of the hierarchy all the way back to the top created some of the most spaghettied spaghetti code you could imagine.


Constantly Named

by in CodeSOD on

We’ve seen constants in the form of static final int ONE = 1 before. At this point, it’s barely worth discussing, it’s become so common. But Susan has found us yet another unique twist on the subject.

It started when a contractor wrote Java code that looked like this:


Uniquier

by in CodeSOD on

Sole Purpose of Visit's team had a simple enough problem: they needed to generate unique labels for widgets on the screen. These widgets just need those unique IDs for internal purposes, so a simple incrementing counter would have been sufficient.

That isn't the direction they went in.


Free Peach

by in Error'd on

In English we have common greetings and farewells that mark salubrious moments in time, such as "Good Morning", "Good Evening", "Good Afternoon", even "Happy New Year" or "Happy Birthday". The same is true for every tongue with which I am even slightly familiar, to the point I will wager that it is common to every human language on the planet. And yet, despite the invention of "le weekend" at least a century ago (variously attributed to labour unionists, Henry Ford, or a nomadic monotheist), even the French have not yet penned a pithy phrase to herald the end of our conventional working week.
Except today.
Today, this one day of the year, we English-speakers have the expression readily at hand: Good Friday.
(If I am wrong about this, and one of your favorite languages actually includes a hackneyed weekend marker, please correct me in the comments.)

Slipping in under the publication deadline wire by the skin of his teeth, our reliable contributor The Beast In Black is back. This time with "A harsh reminder that beer isn't free." I don't recall seeing a 402 in the wild, at least not in the last decade. The error is plausible enough, but the irony itself is error'd-worthy.


Select Your Dropdown

by in CodeSOD on

Francisco's co-worker needed to populate a dropdown with three items: "--All--", "Accepted", and "Pending". Unfortunately for this co-worker, a basic understanding of "array literals" or "lists" or, well, any collection type was slightly beyond their grasp. Instead, they chose to do what many a developer who doesn't understand the date/time functions of their languages does: ask the database for help:

select '--All--' union select 'Accepted' union select 'Pending'

In House Refactoring

by in CodeSOD on

Today's submitter works for a company that has a history of outsourcing pretty much all development, and to the lowest bidder, at that. This resulted in some terrible code, complete with 30,000 line classes, so the company decided to bring development back in house and clean up the code.

After three years of hard work, the in-house team was proud to announce their new, more maintainable, version of the code. Unfortunately, they didn't have the best sense of what maintainable looked like, so their Java code had methods with signatures like this:


Changing the Type of Newbie

by in CodeSOD on

Today's story isn't really a WTF. No, Phil R was mentoring a new developer, and as such, Phil was sending some simple, easily scoped Python tasks over to that developer. After a few really low hanging fruit, Phil gave the Newbie a trickier one. The contact_type field was currently a string. That was a mistake, and it needed to be changed to a number. The change would involve a whole bunch of find-and-replace, but mostly it was just changing strings like '07' into 7.

Newbie trotted off, and found this code block:


The View From Your State

by in Feature Articles on

April Fool's Day happened over the weekend, which means no April Fool's Day post. I mean, I could have, but instead, I thought it would be fun to look into something that, once upon a time, wasn't a WTF, but honestly, always should have been.

Our story starts with Jake, a relatively modern web developer, who was helping another developer, Jane, build a site-scraper for a local government's site. See, the government site couldn't be bothered with anything like RSS, so if you wanted a list of upcoming events, notifications, or other information, your only option was to load the page manually, or whip up a site-scraper that automated extracting that information.