Recent Articles

Jun 2022

Fizzy

by in CodeSOD on

Suri was about to add some new functionality to an existing application, and since it was a relatively big change, she spent a few hours tidying up the codebase. Sitting in there, in the code actually running in production, she found this:

/** * The VehicleConfigurationModel class. */ public class VehicleConfigurationModel { public static void main(String[] args) { for (int counter = 0; counter <= 20; counter++) { if(counter % 3 == 0){ System.out.print("Fizz"); } if (counter % 5 == 0){ System.out.print("Buzz"); } else { System.out.print(counter); } System.out.println(""); } } }

If You Switch

by in CodeSOD on

Switches are great. Given a value, you can switch to different code paths based on that value. The problem is… what if you have other conditions too?

Well, Hubert's co-worker found a way around that. Here's a heavily anonymized version of the pattern.


By Template

by in CodeSOD on

Kimberly L sends us an example of what is clearly template-generated code, so I think this is an opportunity to go on a rant.

Now, the important thing to note here is that this code was in a packaged library that they were considering using.


The Next Version

by in Feature Articles on

Frequent contributor Argle (previous) is mildly famous, and not just around here. He writes:

Someone once remarked that they were jealous that I had two Wikipedia articles written about projects I created. This is about one of them.


Anno Domini

by in Error'd on

Buffalo, New York is a recovering Rust Belt city which has given the world several notable achievements. First, a fairly forgettable sliced meat sandwich au jus more known for its barely edible stale roll than for the entirely unremarkable beef entombed within. Second, an innovative repurposing of a castoff fowl appendage into a drunkard's delicacy (and Mlle Simpson's famed befuddlement). Most of all, it's indispensable for the construction of a lighthearted linguistic shibboleth: Buffalo buffalo buffalo buffalo... and so on. Unfortunately, the city also brings us bad news this week.

But first, Tony H. reminds us of a famously scandal-ridden bank. Theirs might not have been the worst fraud in 2016 (or 2017, or 2018, or 2019) but apparently they're now tightening down the screws on consumer lending. Tony observes, frostily, "a credit card with a limit below zero is alarming even for Wells Fargo."


Submit Your Vacation

by in Feature Articles on

"We have an internal website that shows, among other things, the daily availability of my coworkers for the next three months to help with scheduling, especially when planning vacations," writes Alexander.

"This vacation planner data is represented as a table. An image of a table to be more precise."


Heading On Out

by in CodeSOD on

Madeline inherited some Python 2.7 code, with an eye towards upgrading it to a more modern Python version. This code generates CSV files, and it's opted to do this by cramming everything into a 2D array in memory and then dumping the array out with some join operations, and that's the real WTF, because that's a guaranteed way to generate invalid CSV files. Like so many things, the CSV files are actually way more complicated than people think.

But we're going to focus in on a smaller subset of this pile of WTFs. I'll lead with the caveat from Madeline: "I've changed some of the variable names around, for a bit of anonymity, but couldn't get variable names quite as terrible as the original ones."


Show Thumbnails?

by in CodeSOD on

Christopher Walker continues to struggle against ancient PHP applications in the automotive industry. With the point system behind him, there was a whole pile of internal applications for handling information about laws, misconceptions about the law, and other driver services.

One, a home-grown CMS, was useful for publishing blog-style content about changes in the law. There was just one problem: if a post was published without a thumbnail, attempts to view that post failed with an error. It wasn't hard to find the offending line.


Spellchucker

by in CodeSOD on

There's an old saying in programming: you don't have to spell correctly, you only have to spell consistently. As long as you mispell everything the same way, your language will understand your code. However, most editors and IDEs have spell-check integration, though, because it's hard to get everyone on a team to spell things wrong consistently.

Unless, of course, you know just implement some bonus methods, like John's co-worker. This was frequently spammed in the Java codebase:


Classic WTF: Pure Eval

by in CodeSOD on
We close out our week with something evil. Someting… eval. Original. --Remy

When Jeff saw a line like this one, he knew there was something terribly wrong in the code he had inherited.

eval(Application("buildCommon").toString());


Classic WTF: GHOST Busted

by in Feature Articles on
We're wrapping up our vacation week with a look at something really scary. A GHOST. A spooky GHOST, not the Swedish metal band, which isn't really spooky. Original. --Remy

Some developers look at a problem and say, “Let’s solve it. With code!” Then there are other developers, who say, “This specific problem is a subset of a general class of problem, which, if we solve the general class, will automatically solve the specific class.” The best programmers know when it’s time to keep it simple, and when they really should shoot for the stars.

Chris worked for a startup run by former academics. They wanted to shoot for the stars, some black holes, and maybe, if there was budget left over, the primordial galaxies that formed after the Big Bang. They had an idea for a product which would… well, Chris had no idea what it did.

The vision was codenamed SPRIT. Walter, the wizard behind it, couldn’t explain its purpose in terms anyone else understood. The only thing he could explain was that SPIRIT needed to be implemented in the in-house language, GHOST. “It’s a joke,” Walter explained once, “It stands for ‘Generic Hybrid Script for Transactional Objects’. The acronym is out of order because GHOST is all about parallel processing. It’s funny.”


Classic WTF: Back That Thang Up

by in Feature Articles on
We're still away for our summer break, skimming our inbox and horrified by all the things you're sending us. Keep doing it. Speaking of horrors, this one's about backups. You know what's about to happen… Original. -- Remy

It ain't easy being number one, especially for R.B.'s company. With €730 million in annual revenues, they're the leader in a relatively small (€1.6 billion) niche market and are constantly struggling to maintain their dominance amongst a handful of vicious competitors. Recently, an executive at the company came up with an astonishingly brilliant plan that would ensure that they stayed on top for many years to come. This plan was named The Convergence.

The Convergence was, in all seriousness, a really good idea. It represented a completely new way of doing business that relied heavily on technology and its ability to integrate the supply chain with the customer experience. It would do nothing short of revolutionizing their entire industry, leaving their competitors struggling just to stay afloat.


Classic WTF: The Source Control Shingle

by in Feature Articles on
It's still a short summer break for a few more days, as always, keep those submissions filling our inbox while we're away. In the meantime, we're also into peak homebuying season. A friend of mine needed a new roof as part of her purchase. Roofs are important, as they provide vital protection for your structure. Unless that structure is your source code… Original. --Remy

The year was 1999 and the dot-com boom was going full-throttle. Companies everywhere were focused on building revolutionary applications using nothing but top-shelf hardware and state-of-the-art software tools. Developers everywhere were trying to figure out if they should play more foosball, more air hockey, or sit back down on their Aeron and write more code. Everywhere, that is, except Boise, Idaho. Or at least, Dave's small corner of it.

At Dave's company, developers worked at a solid pace, using reliable tools, for a stable industry. They were sub-sub-contractors on a giant project commissioned by the U.S. Navy to condense naval vessel documentation. Generally speaking, the complete documentation required for a modern warship-from the GPS calibration instructions to the giant 130-millimeter cannon repair guide-is measured in tons. By condensing the documentation into the electronic equivalent, they could not only save tremendous physical space, but they could make it much easier to navigate.


Classic WTF: DATABASE ABNORMALIZATION 101

by in Feature Articles on
It's that time of year, we're taking a brief little summer break this week, and thus reaching back into the archives for some classics. Enjoy these, and in the meantime, keep those submissions coming! For today, we have a unique way to keep track of when classes start… Original. --Remy

Working as a DBA in academia, Paul received a notice that a certain newly migrated user schema, specifically the one used by the enrollment tracking system, had swelled to 281 tables and was growing. This had struck Paul as being very strange since the tracking system wasn't all that complicated.

When a student is registering for a class, and want to know if there's room left, they need two pieces of information - the Course ID and the Semester Number.


Meat!

by in Error'd on

I remember when gasoline was under a dollar a gallon in the US! And penny candy was only a penny! And a pound sterling could buy you a decent dinner, not just a few ounces of meat product! And the euro! Let me tell you about the euro!!
I mean, um. Yeah. Things have changed, and it seems lately all our consumer goods and services have become suddenly more expensive, or smaller, or inferior in some other way. Have you priced airplane flights, even in middle seats with no luggage or food?
The lead submission this week isn't really a software Error'd. It's not even a wacky product offering from Amazon. But despite what seems an unconscionable price, the manufacturer has discovered a revolutionary method to deliver extra value by (apparently) literally altering the properties of the universe.
Ladies and gentlemen, I give you... MEAT!

Finally free from those awful EU restrictions, Michael R. now has access to 85% over-clocked pork sausages. "Not bad to get 185g meat out of 100g product.", he grunts gluttonously. "I will take 2."


Re-Ports

by in CodeSOD on

Crystal Reports falls into that category of tool which promises to help end users accomplish technical tasks easily. They can point it at a database, ask the database a question, and voila, a report pops out, complete with pretty fonts and colors.

Like any such tool, however, there's a point where it starts getting technical. Jon's company passed that point ages ago, and hired on a dedicated Crystal Reports Developer to write reports that were too complicated for the end users. But even that has its limits, and eventually, their reporting needs outgrew what a Crystal Report implemented by their dedicated developer could do.


Query Lockup

by in CodeSOD on

Another day, another time where someone from Brian's team needs to log into their MySQL database and kill a query. This particular query hangs while holding a lock, which hangs up every other query which needs to touch this table, which is a lot of them.

select count(*) INTO @fullCount FROM SALLSTDM LEFT OUTER JOIN BUYBIDMB ON (MBBUYNBR = 597436 AND MBLOTNBR = SLLOTNBR) INNER JOIN LOTFILFL FL1 ON (FL1.FLFILTYP = 'A1' AND FL1.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL2 ON (FL2.FLFILTYP = 'A1' AND FL2.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL3 ON (FL3.FLFILTYP = 'A1' AND FL3.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL4 ON (FL4.FLFILTYP = 'A1' AND FL4.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL5 ON (FL5.FLFILTYP = 'A1' AND FL5.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL6 ON (FL6.FLFILTYP = 'A1' AND FL6.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL7 ON (FL7.FLFILTYP = 'A1' AND FL7.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL8 ON (FL8.FLFILTYP = 'A1' AND FL8.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL9 ON (FL9.FLFILTYP = 'A1' AND FL9.FLLOTNBR = SALLSTDM.SLLOTNBR ) INNER JOIN LOTFILFL FL10 ON (FL10.FLFILTYP = 'A1' AND FL10.FLLOTNBR = SALLSTDM.SLLOTNBR ) WHERE 1=1 AND SALLSTDM.SLYRDNBR not in(450,451,452)

Mostly Okay

by in CodeSOD on

Taffer is the team lead on a team making security products. As such, they have very strict policies about how they write their code, they have very thorough code review systems, and they also have automated tests for everything.

And yet, things can still slip through.


onFunctionCall

by in CodeSOD on

Annalise has a pile of… unfortunate JavaScript. It's thousands of files with no real organization or logic behind their organization. It's got so much tech debt that it takes a full time developer just to keep it running, let alone provide support or add features or fix bugs. And the backlog of features and bugs is so long that it's best described in terms of א.

Which is to say, there's a lot in there that nobody understands. So when you see a bunch of callbacks registered to onFunctionCall, you might assume that this handler is doing… something. You'd be wrong.


Cinch

by in Error'd on

Yankee Ezra A. explains the screenshot below at some length. Says he: "I live in Newton, MA, an affluent, wealthy suburb of Boston. In general, city services are excellent, although the home page of the website is a bit crowded, so I was glad to get an email with a link to the page where I could see how the city is handling my request/complaint about sidewalks, via the city's 311 service (I have no idea what the 311 stands for) When I went to the website, I found what you see in the photo. I guess one can't really complain about one small error in a large website." It's certainly an effective strategy for keeping the complaints box empty!


Typos

by in Feature Articles on

Guillaume's company frequently uses consultants. It's a pretty standard setup: Guillaume's employer has many multi-year projects in flight, all of which are layered atop an existing ecosystem of in-house "do everything" applications, each full of their own WTFs.

Because of the complexity, Guillaume's team has a pretty strict code review policy. Someone new to the team will write a merge request, a senior developer will coldly review it and provide huge amounts of comments. By the end of the process, the senior team member may have provided most of the code and architecture via those code review comments, and the junior member is left to just follow the instructions.


True Enough

by in CodeSOD on

Managing true and false values is historically challenging. In the world of C, there's even a history to those challenges. Prior to the C99 standard, there wasn't a standardized version of boolean values, but there was a convention which most applications followed, based on how C conditionals and boolean logic works.

In C, anything non-zero is considered "true". So, if(0) { … } won't execute the branch, but if(99) { … } will. As a result, when people wanted to make boolean equivalents, they'd use the C preprocessors to specify something like: