![]() |
by Remy Porter on (#6SQCJ)
Eli sends us something that's not quite a code sample, despite coming from code. It's not a representative line, because it's many lines. But it certainly is representative.Here's the end of one of their code files:
|
The Daily WTF
Link | http://thedailywtf.com/ |
Feed | http://syndication.thedailywtf.com/TheDailyWtf |
Updated | 2025-07-04 00:15 |
![]() |
by Remy Porter on (#6SPF5)
As often happens, Luka started some work but didn't get it across the finish line before a scheduled vacation. No problem: just hand it off to another experienced developer.Luka went off for a nice holiday, the other developer hammered away at code, and when Luka came back, there was this lovely method already merged to production, sitting and waiting:
|
![]() |
by Remy Porter on (#6SNMS)
"We use a three tier architecture," said the tech lead on Cristian's new team. "It helps us keep concerns separated."This statement, as it turned out, was half true. They did divide the application into three tiers- a "database layer", a "business layer", and a "presentation layer". The "database layer" was a bunch of Java classes. The "business layer" was a collection of Servlets. And the "presentation layer" was a pile of JSP files.What they didn't do, however, was keep the concerns separated.Here's some code from their database layer:
|
![]() |
by Remy Porter on (#6SMVH)
Alexandra inherited a codebase that, if we're being kind, could be called "verbose". Individual functions routinely cross into multiple thousands of lines, with the longest single function hitting 4,000 lines of code.Very little of this is because the problems being solved are complicated, and much more of it is because people don't understand how anything works.For example, in this C++ code, they have a vector of strings. The goal is to create a map where the keys are the strings from the vector, and the values are more strings, derived from a function call.Essentially, what they wanted was:
|
![]() |
by Lyle Seaman on (#6SK12)
...or actually, it doesn't. A few fans found figures that just didn't add up. Here they are.Steven J Pemberton deserves full credit for this finding."My bank helpfully reminds me when it's time to pay mybill, and normally has no problem getting itright. But this month, the message sent Today 08:02,telling me I had to pay by tomorrow 21-Nov was senton... 21-Nov. The amount I owed was missing the decimal point. They then apologisedfor freaking me out, but got that wrong too, by notreplacing the placeholder for the amount I really needed to pay."
|
![]() |
by Erik Gern on (#6SJA6)
|
![]() |
by Remy Porter on (#6SHD7)
Today, we're going to start with the comment before the method.
|
![]() |
by Remy Porter on (#6SGHK)
Robert was diagnosing a problem in a reporting module. The application code ran a fairly simple query- SELECT field1, field2, field3 FROM report_table- so he foolishly assumed that it would be easy to understand the problem. Of course, the "table" driving the report wasn't actually a table, it was a view in the database.Most of our readers are familiar with how views work, but for those who have had been corrupted by NoSQL databases: database views are great- take a query you run often, and create it as an object in the database:
|
![]() |
by Remy Porter on (#6SFM5)
"Magic bytes" are a common part of a file header. The first few bytes of a file can often be used to identify what type of file it is. For example, a bitmap file starts with "BM", and a PGM file always starts with "PN" where "N" is a number between 1 and 6, describing the specific variant in use, and WAV files start with "RIFF".Many files have less human-readable magic bytes, like the ones Christer was working with. His team was working on software to manipulate a variety of different CAD file types. One thing this code needed to do is identify when the loaded file was a CAD file, but not the specific UFF file type they were looking for. In this case, they need to check that the file does not start with 0xabb0, 0xabb1, or 0xabb3. It was trivially easy to write up a validation check to ensure that the files had the correct magic bytes. And yet, there is no task so easy that someone can't fall flat on their face while doing it.This is how Christer's co-worker solved this problem:
|
![]() |
by Lyle Seaman on (#6SDQ9)
"Because 9.975 was just a *little* bit too small," explains our firstanonymous helper.
|
![]() |
by Remy Porter on (#6SCVZ)
Charles is supporting a PHP based application. One feature of the application is a standard "Contact Us" form. I'll let Charles take on the introduction:
|
![]() |
by Remy Porter on (#6SBXH)
Once upon a time, web browsers weren't the one-stop-shop for all kinds of possible content that they are today. Aside from the most basic media types, your browser depended on content plugins to display different media types. Yes, there was an era where, if you wanted to watch a video in a web browser, you may need to have QuickTime or... (shudder) Real Player installed.As a web developer, you'd need to write code to check which plugins were installed. If they don't have Adobe Acrobat Reader installed, there's no point in serving them up a PDF file- you'll need instead to give them an install link.Which brings us to Ido's submission. This code is intended to find the Acrobat Reader plugin version.
|
![]() |
by Remy Porter on (#6SAYQ)
Sometimes, there's code so bad you simply know it's unused and never called. Bernard sends us one such method, in Java:
|
![]() |
by Remy Porter on (#6SA0X)
Simon recently found himself working alongside a "very senior" developer- who had a whopping 5 years of experience. This developer was also aggrieved that in recent years, Object Oriented programming had developed a bad reputation. "Functional this, functional that, people really just don't understand how clean and clear objects make your code."For example, here are a few Java objects which they wrote to power a web scraping tool:
|
![]() |
by Lyle Seaman on (#6S869)
...Screens of Death. Photos of failures in kiosk-mode always strike me as akin to the wizard being exposed behind his curtain. Yeah, that shiny thing is after all just some Windows PC on a stick. Here are a few that aren't particularly recent, but they're real.Jared S. augurs ill: "Seen in downtown Mountain View, CA: In Silicon ValleyAI has taken over. There is no past, there is no future,and strangely, even the present is totally buggered. However, you're free to restore the present if you wish."
|
![]() |
by Remy Porter on (#6S79D)
ArSo works at a small company. It's the kind of place that has one software developer, and ArSo isn't it. But ArSo is curious about programming, and has enough of a technical background that small tasks should be achievable. After some conversations with management, an arrangement was made: Kurt, their developer, would identify a few tasks that were suitable for a beginner, and would then take some time to mentor ArSo through completing them.It sounded great, especially because Kurt was going to provide sample code which would give ArSo a head start on getting things done. What better way to learn than by watching a professional at work?
|
![]() |
by Remy Porter on (#6S6AB)
Alicia recently inherited a whole suite of home-grown enterprise applications. Like a lot of these kinds of systems, it needs to do batch processing. She went tracking down a mysterious IllegalStateException only to find this query causing the problem:
|
![]() |
by Remy Porter on (#6S5CG)
Some time ago, poor Keith found himself working on an antique Classic ASP codebase. Classic ASP uses VBScript, which is like VisualBasic 6.0, but worse in most ways. That's not to say that VBScript code is automatically bad, but the language certainly doesn't help you write clean code.In any case, the previous developer needed to make an 8 element array to store some data. Traditionally, in VBScript, you might declare it like so:
|
![]() |
by Remy Porter on (#6S4HN)
Ross needed to write software to integrate with a credit card payment gateway. The one his company chose was relatively small, and only served a handful of countries- but it covered the markets they cared about and the transaction fees were cheap. They used XML for data interchange, and while they had no published schema document, they did have some handy-dandy sample code which let you parse their XML messages.
|
![]() |
by Lyle Seaman on (#6S2NY)
Amateur physicist B.J. is going on vacation, but he likes to plan things right down to the zeptosecond."Assume the flight accelerates at a constant speed for the first half of the flight, and decelerates at the same rate for the second half. 1) What speed does the plane need to reach to have that level of time dilation? 2) What is the distance between the airports?"
|
![]() |
by Remy Porter on (#6S1TS)
Matt needed to add a new field to a form. This simple task was made complicated by the method used to save changes back to the database. Let's see if you can spot what the challenge was:
|
![]() |
by Remy Porter on (#6S0YA)
There's the potential for endless installments of "programmers not understanding how UUIDs work." Frankly, I think the fact that we represent them as human readable strings is part of the problem; sure, it's readable, but conceals the fact that it's just a large integer.Which brings us to this snippet, from Capybara James.
|
![]() |
by Remy Porter on (#6S001)
Since it's election day in the US, many people are thinking about counting today. We frequently discuss counting here, and how to do it wrong, so let's look at some code from RK.This code may not be counting votes, but whatever it's counting, we're not going to enjoy it:
|
![]() |
by Remy Porter on (#6RZ41)
For years, Victoria had a co-worker who "programmed by Google Search"; they didn't understand how anything worked, they simply plugged their problem into Google search and then copy/pasted and edited until they got code that worked. For this developer, I'm sure ChatGPT has been a godsend, but this code predates its wide use. It's pure "Googlesauce".
|
![]() |
by Lyle Seaman on (#6RXBK)
"Check out Visual Studio optimizing their rating system toonly include the ratings used," sharedFiorenzo R. Imagine the performance gain!
|
![]() |
by Remy Porter on (#6RWF5)
Horror movies, as of late, have gone to great lengths to solve the key obstacle to horror movies- cell phones. When we live in a world where help is a phone call away, it's hard to imagine the characters not doing that. So screenwriters put them in situations where this is impossible: in Midsommar they isolate them in rural Sweden, in Get Out calling the police is only going to put our protagonist in more danger. But what's possibly more common is making the film a period piece- like the X/Pearl/Maxxxine trilogy, Late Night with the Devil, or Netflix's continuing series of R.L. Stine adaptations.I bring this up, because today's horror starts in 1993. A Norwegian software company launched its software product to mild acclaim. Like every company, it had its ups and downs, its successes and missteps. On the surface, it was a decent enough place to work.Over the years, the company tried to stay up to date with technology. In 1993, the major languages one might use for launching a major software product, your options are largely C or Pascal. Languages like Python existed, but weren't widely used or even supported on most systems. But the company stayed in business and needed to update their technology as time passed, which meant the program gradually grew and migrated to new languages.Which meant, by the time Niklas F joined the company, they were on C#. Even though they'd completely changed languages, the codebase still derived from the original C codebase. And that meant that the codebase had many secrets, dark corners, and places a developer should never look.Like every good horror movie protagonist, Niklas heard the "don't go in there!" and immediately went in there. And lurking in those shadows was the thing every developer fears the most: homebrew date handling code.
|
![]() |
by Remy Porter on (#6RVHN)
Once again, we take a look at the traditional "if (boolean) return true; else return false;" pattern. But today's, from RJ, offers us a bonus twist.
|
![]() |
by Remy Porter on (#6RTNW)
Jon recently started a new project. When setting up his dev environment, one of his peers told him, "You can disable verbose logging by setting DEBUG_LOG=false in your config file."Well, when Jon did that, the verbose logging remained on. When he asked his peers, they were all surprised to see that the flag wasn't turning off debug logging. "Hunh, that used to work. Someone must have changed something..." Everyone had enough new development to do that tracking down a low priority bug fell to Jon. It didn't take long.
|
![]() |
by Remy Porter on (#6RSQA)
Quality control is an important business function for any company. When your company is shipping devices with safety concerns, it's even more important. In some industries, a quality control failure is bound to be national headlines.When the quality control software tool stopped working, everyone panicked. At which point, GRH stepped in.Now, we've discussed this software and GRH before, but as a quick recap, it was:
|
![]() |
by Lyle Seaman on (#6RQYD)
No obvious pattern fell out of last week's submissions for Error'd, but I did especially like Caleb Su's example.Michael R., apparently still job hunting, reports "I have signed up to outlier.ai to make some $$$ on the side. No instructions necessary."
|
![]() |
by Remy Porter on (#6RQ33)
As a general rule, if you're using an RDBMS and can solve your problem using SQL, you should solve your problem using SQL. It's how we avoid doing joins or sorts in our application code, which is always a good thing.But this is a general rule. And Jasmine sends us one where solving the problem as a query was a bad idea.
|
![]() |
by Remy Porter on (#6RP5B)
When processing HTTP requests, you frequently need to check the parameters which were sent along with that request. Those parameters are generally passed as stringly-typed key/value pairs. None of this is news to anyone.What is news, however, is how Brodey's co-worker indexed the key/value pairs.
|
![]() |
by Remy Porter on (#6RN74)
Our stories come from you, our readers- which, it's worth reminding everyone, keep those submissions coming in. There's nothing on this site without your submissions.Now, we do get some submissions which don't make the page. Frequently, it's simply because we simply don't have enough context from the submission to understand it or comment on it effectively. Often, it's just not that remarkable. And sometimes, it's because the code isn't a WTF at all.So I want to discuss some of these, because I think it's still interesting. And it's unfair to expect everyone to know everything, so for the submitters who discover they didn't understand why this code isn't bad, you're one of today's lucky 10,000.We start with this snippet, from Guss:
|
![]() |
by Remy Porter on (#6RMAP)
When SC got hired, the manager said "unit testing is very important to us, and we have 100% test coverage."Well, that didn't sound terrible, and SC was excited to see what kind of practices they used to keep them at that high coverage.
|
![]() |
by Lyle Seaman on (#6RJGN)
The most common type of submission Error'd receivesare simple, stupid, data problems on Amazon. The textdoesn't match the image, the pricing is goofy, or someother mixup that are just bound to happen with a databaseof zillions of products uploaded by a plethora ofbarely-literate mountain village drop-shippers.So I don't usually feature them, preferring to find something with at least a chance of being a creative new bug.But I uncovered a story by Mark Johansen about his favoriteauthor, and decided that since so many of you obviously DO thinkonline retail flubs are noteworthy, what the heck.Here is Mark's plain-text story, and a handful of bungledproducts. They're not exactly bugs, but at least some ofthem are about bugs."I guess I missed your item about failings of AI, but here's one of my favorites:Amazon regularly sends me emails of books that their AIthinks I might want to read, presumably based on booksthat I've bought from them in the past. So recently Igot an email saying, "The newest book by an author you'veread before!" And this new book was by ... Ernest Hemingway.Considering that he died almost 60 years ago, it seemedunlikely that he was still writing. Or where he wassending manuscripts from.Lest you wonder, it turned out it was a collection ofletters he wrote when he was, like, actually alive. Thebook was listed as authored by Ernest Hemingwayrather than under the name of whomever compiled the letters."What do we all think? Truly an Error'd, or just some publishertaking marketing advice from real estate agents? Let me know.A while back, Christian E."Wanted to order some groceries from nemlig.com. So I saw the free (labelled GRATIS) product and pressed the info button and this popped up. Says that I can get the product delivered from the 1st of January (today is the 2nd of march). Have to wait for a while then..." Not too much longer, Christian.
|
![]() |
by Remy Porter on (#6RHMV)
Damiano's company had more work than staff, and opted to hire a subcontractor. When hiring on a subcontractor, you could look for all sorts of things. Does their portfolio contain work similar to what you're asking them to do? What's the average experience of their team? What are the agreed upon code quality standards for the contract?You could do that, or you could hire the cheapest company.Guess which one Damiano's company did? If you're not sure, look at this code:
|
![]() |
by Remy Porter on (#6RGNS)
Dennis found this little nugget in an application he inherited.
|
![]() |
by Remy Porter on (#6RFRK)
"Oh, I see what you mean, I'll just write an overloaded function which takes the different set of parameters," said the senior dev.That got SB's attention. You see, they were writing JavaScript, which doesn't have function overloading. "Um," SB said, "you're going to do what?""Function overloading," the senior dev said. "It's when you write multiple versions of the same method with different signatures-""I know what it is," SB said. "I'm just wondering how you're going to do that in JavaScript.""Ah," the senior dev said with all the senior dev wisdom in the world. "It's a popular misconception that function overloading isn't allowed in JavaScript. See this?"
|
![]() |
by Remy Porter on (#6REYA)
Jason was investigating a bug in a bitmask. It should have been set to 0b11, but someone had set it to just plain decimal 11. The line responsible looked like this:
|
![]() |
by Lyle Seaman on (#6RD35)
...to know which way the wind blows.This week, it's been an ill one. Two of our readers sent us references to the BBC's reports on unusual weather in Bristol - one from the web, and one mobile. Maybe that will help you deduce the source of this error.Frist, Graham F. shared a screenshot of the beeb's mobile app, bellowing"I know Milton is hitting the US hard right now but that'snothing compared to the 14,000 mph winds here!"
|
![]() |
by Remy Porter on (#6RC8R)
Working at a company where the leadership started as technical people has its advantages, but it can also carry costs. Arthur is in one such environment, and while it means that management and labor have a common vocabulary, the company leadership forgets that they're not in a technical role anymore. So they still like to commit code to the project. And that's how things like this happen:
|
![]() |
by Remy Porter on (#6RBA1)
Let's say you have a web application, and you need to transfer some data that exists in your backend, server-side, down to the front-end, client-side. If you're a normal person, you have the client do an HTTP request and return the data in something like a JSON format.You could certainly do that. Or, you could do what Alicia's predecessor did.
|
![]() |
by Remy Porter on (#6RAAE)
Ben's web firm took on a new client, and they're using a rather questionable shopping cart system. Like a lot of PHP web plugins, someone decided that they needed to "protect" their code by obfuscating it. Either that, they were obfuscating it out of shame, one or the other.
|
![]() |
by Remy Porter on (#6R9BS)
The power of exception handling is that it allows every layer in our stack be notified of an error condition, do something about it, and pass it on if necessary.For example, if you have a data access layer and a query fails, you may catch the exception and potentially retry there, only passing the exception up the stack after a few failures. Or, you may fail to connect, updates some internal status variables to represent that you're in an invalid state, and then pass that exception up the stack.There are other options one might use for propagating errors, but many languages use structure exception handling.Which brings us to today's anonymous submission, which is more of a representative comment than a representative line. This was in the public interface to the data access layer in a project:
|
![]() |
by Lyle Seaman on (#6R7KK)
I am amused to see that Warcraft III isstill out there being played. I think it was my son's first PC game and maybe the second to last one I ever played regularly.And it's Maia E. who's doing it. She reports "Warcraft III was patched into oblivion over the years,and it looks like the patches introduced some bugs intocampaign quests. At least they didn't rename Thrall into(undefined)!"
|
![]() |
by Remy Porter on (#6R6PV)
Alexander doesn't usually ask "why are you hiring for this position?" during an interview. But when a small public library is paying your rather high contracting rate, one can't help but wonder. Fortunately, the library offered their reasoning without Alexander asking: "We hired a new staff member, so we need a programmer to add them to our home page."Alexander assumed that he was dealing with a client who couldn't figure out how to navigate their CMS, and scheduled an afternoon to do the work. It turned out to be a bit more complicated.The site had an "email a staff member" form. Select a staffer from a drop down, type into a text box, and hit send. Not a single staff member had ever received an email through the interface, but they all agreed it was a good feature to have, even if no one used it.The relationship between staff members and email addresses was stored in a database. I'm kidding, why would you use a database for that? It was stored in a PHP file called mail_addresses.php:
|
![]() |
by Remy Porter on (#6R5TM)
Seuf sends us some old code, which entered production in 2011. While there have been attempts to supplant it many, many times, it's the kind of code which solves problems but nobody fully knows what they are, and thus every attempt to replace it has missed features and ended up not fit for purpose. That the tool is unmaintainable, buggy, and slow? Well, so it goes.Today's snippet is Perl:
|
![]() |
by Remy Porter on (#6R4VB)
Jason started work on a C++ application doing quantitative work. The nature of the program involves allocating all sorts of blocks of memory, doing loads of complicated math, and then freeing them. Which means, there's code which looks like this:
|
![]() |
by Remy Porter on (#6R400)
We've seen so many home-brew string padding functions. And yet, there are still new ways to do this wrong. An endless supply of them. Nate, for example sent us this one.
|
![]() |
by Lyle Seaman on (#6R21G)
"Clouds obscure the result," reportsMike T.'s eight-ball."It's a shame when the cloud and the browser disagree," he observed.
|