Feed the-daily-wtf The Daily WTF

Favorite IconThe Daily WTF

Link http://thedailywtf.com/
Feed http://syndication.thedailywtf.com/TheDailyWtf
Updated 2025-06-01 20:01
Error'd: All Michael
One of our most dedicated readers, Michael R., is also one of our most dedicated contributors,sometimes sending us several submissions in a single day. We haven't featuredall of them, but now we're making up for that. Today, it'swall-to-wall Michael, mostly food misadventures. Michael might tell you we'vecooked the plot, but he can't prove it.On leaving France (it's a long story), Michael was confused at the airport."Yo Sushi at Charles de Gaulle Terminal, please make upyour mind about what payment types you accept." I think this one is pretty clear;just because a sign says they accept one form of paymentit doesn't mean they categorically reject all others. So if your card is on eithersign, you're covered. I hope he got fed.
CodeSOD: Broken Loop
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.
CodeSOD: Gonna Need an Extension
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.
CodeSOD: Terminated Nulls
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.Now, Dan's predecessor wanted to do exactly that: open a file for writing, with 4096 records.This was their C code for doing that:
CodeSOD: A Mid Query
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:
Error'd: Just a Taste
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."
CodeSOD: Time for Oracle
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#:
CodeSOD: Maximizing Code Quality
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.The JavaScript started like this:
CodeSOD: I saw the Vorzeichen
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:
CodeSOD: A Type of Alias
Joe inherited some C code that left him scratching his head.It doesn't start too badly:
Error'd: Beer and Peanuts
We got a lot of good submissions this week, includingsome examples of test-in-prod we're saving for a specialedition. Not too many of the usual NaN/Null/Undefined sort, but we did also get a small rash of time failures.But frist, Henk highlights the curious case of QNAP's email subscription management page (which appears to be outsourced)."QNAP surely does not want to lose me!" he hoped.
Structure is Structure
Back in the heady days of the DotCom Bubble, startups were thick on the ground, and Venture Capital money was a flood- lifting startups atop a tsunami only to crash them back into the ground a short time later. Taliesyn once worked for one such startup.Taliesyn's manager, Irving, was an expert in AI. In the age of the DotCom Bubble, this meant Irving knew LISP. Knowing LISP was valuable here, because their core product was a database system built on LISP- specifically the Common LISP Object System, an object-oriented bolt-on for LISP.It was an object-oriented database system, akin to the modern NoSQL databases, but its architecture left a few things to be desired. First, since disk reads and writes were expensive operations, the system avoided them. All updates to data were done in memory, and someday, at some point, when the program felt like it, the changes would be written to disk. This meant that any failures or crashes could lose potentially days of data. Worse, the data was stored in one gigantic text file, which meant corruption could easily take out the entire database.These were legitimate problems, and due to the architecture, they were going to be challenging to resolve. That was the startup life, however- they had a minimum viable product, and just needed to pour energy into making it something worth using.Everyone looked to Irving, the AI and LISP expert, to guide them through this.Irving saw where the real problems lay. "Your database doesn't support SQL," Irving said."Well, sure," Taliesyn said. "That's our selling point."Irving nodded, and then, speaking slowly, as if to a particularly dense child, said, "A database needs to support SQL.""I mean, a relational database, sure," Taliesyn said, "but we're using an object oriented data model which means we don't need to do joins or-" Taliesyn kept talking, explaining why their database didn't support SQL, why it shouldn't support SQL, and why SQL support was not only off the roadmap, but so far off the roadmap that it was labelled "Here there be dragons."Irving nodded along, and ended the conversation with a, "Sure, that makes sense."Everything was fine for a few weeks, until one of Taliesyn's peers on a different team, Angela, shot him an email: "Hey, marketing is getting antsy about a SQL demo, and I've got half a dozen features blocked until you get me a build with that functionality. What's the timeline like?"Taliesyn was uncertain about what the timeline was like, since he had now clearly slipped into a parallel universe. He politely informed his peer that he had no idea what was going on, but would find out. It didn't take a great sleuth to figure out that Irving had started appending his own features to the roadmap.Taliesyn tracked Irving down and demanded to know what was going on."A customer is already using it!" Irving protested. "They wrote it themselves! So we should be able to do it easily. Frankly, it's embarrassing to say that we can't do something with our own tools that the customer is already doing!"Taliesyn knew that Irving was either wrong or lying, and asked to talk to the customer. Irving was, in fact, wrong. The customer had used LISP to write an extension to their object database (another one of those selling point features), and this extension used ODBC to open a connection to a relational database. This let them move data between the two different database systems."Irving," Taliesyn said, "they're not using SQL on our database, they're connecting to a relational database and using SQL there. SQL doesn't make sense for our data structure! We don't have tables, or keys, or relationships. It's objects! You're promising features that we can't deliver."Irving was unmoved. "We are making a database. A database must have SQL capability. It's structured query language- it's right there in the name! Our structure should be queried by structured query language."Taliesyn tried going over Irving's head, but upper management had no interest in actually solving personnel problems. Irving's buzzword laden ideas about why SQL was required seemed to jive with what their customers wanted, and the idea of shipping a non-SQL database was getting lost in the endless quest for the next round of VC funding.The result was a bolted on monster of broken implementations of SQL that infuriated the few customers who tried it, Irving got promoted, and Taliesyn ran as far from the trainwreck as possible before the company flamed out. [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!
CodeSOD: A Serial Offender
Michael has a confession. Once upon a time, a very long time ago, he needed to write some JavaScript to serialize data and send it as part of a request. The challenge for Michael is that he didn't actually know JavaScript or what its built in functions could do and the task was already past the deadline by the time it got assigned to him.
CodeSOD: Chat about C
I've known a surprising number of developers who say, "Why use any higher level abstractions, you can just do this all in C, and the code will be cleaner and easier to read." Sometimes, they're right. Other times... not so much. And then there are the developers who find C too abstract for their tastes, and eschew things like structs.That's what Renee encountered when inheriting a chat server written in C. I'm guessing it was an IRC server, based on some terminology in the code.
CodeSOD: Classic WTF: An Ant Pushes a Perl
Error'd: It's Our Party
...and we'll cry though we really don't want to.Celebrant Joe cheered "Happy birthday DailyWTF! My gift to you, yet anotherdate related Error'd for the pile."
A Date This Weekend?
Alan worked on a website which had a weekly event which unlocked at 9PM, Saturday, Eastern Time. The details of the event didn't matter, but this little promotion had been running for about a year and a half, without any issues.Until one day, someone emailed Alan: "Hey, I checked the site on Sunday, and the countdown timer displays 00:00:00."Alan didn't check their email on Sunday, and when they checked the site, everything was fine, so he set himself a reminder to check things out next Sunday, and left things alone for a week.Well, Alan forgot on Sunday. It was his day off after all, but he did remember to check first thing on Monday. When he came in, the timer read 00:00:00. Alan had a twelve o'clock flasher. Oddly, when he checked it after grabbing some coffee, the timer now showed the correct value.It was time to dig through the code. Now, this story happened quite some time ago, so the countdown timer itself was a Flash widget. But the widget received a parameter from the HTML DOM, which itself was generated by PHP, and it didn't take long to find the SQL query it was using to find the next event: SELECT next_event FROM event_timer.Yes, event_timer was a one column, one row table. A quick search through the codebase found the table referenced only one other place: backend_settimer.php.All the pieces came together: resetting the timer was an entirely manual process. Every Monday, Tina came in, and assuming she remembered, she reset the timer. Some days she did it late, or forgot entirely. Some weeks, she was on vacation. Maybe she remembered to delegate, maybe she didn't.For roughly 72 weeks, this had been how things had been working.The good news was that the date was getting parsed with the PHP strtotime function, which meant Alan merely had to go to the backend_settimer.php and set the value to Next Saturday 9pm, and let Tina know she didn't need to do this anymore. [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!
Representative Line: Falsehoods Programmers Believe About Name Length
We're all used to Java class names that are... verbose.Arno sends us a representative Java line, which demonstrates that this doesn't end with class names.
CodeSOD: Regional Variation
Visual Studio and the .NET languages support a feature known as "regions". Enclosing a block of code between #region SomeName and #endregion creates collapsible regions in the text editor.It can, in principle, help you organize your code. It does, in practice, make code like this, from Mark, possible."What do you mean, 'single responsibility principle?' This has one job! ADD A CLAIM. How can it get simpler than that?"The upshot of this, is that it's easier to see how one might refactor this function into multiple functions which collaborate. The downside is that this code has been like this for years. As a very bureaucratic insurance company, any refactoring efforts need to be budgeted for, you can't just refactor while working on other tickets- that's "misusing the budget".Instead, we get to enjoy the idea of simple functions, without actually having simple functions. [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!
CodeSOD: Delectable Code
Good method names are one of the primary ways to write self-documenting code. The challenge there, is that documentation often becomes out of date.Take this delectable PHP nugget, from Nathaniel P, who has previously been tortured by bad date handling.
Error'd: ABQ is the bomb
This week we have an unusual number of submissions involving dates or timestamps.That is, the usual sorts of error'ds, but unusually many of them.Gerald E. chuckled "I do love the back to the future movies. Butnow I can see Beck from the future."
CodeSOD: Scoring the Concatenation
Today's a simple one. We've all seen code that relies too heavily on string concatenation and eschews useful methods like Join.Nick L sends us this VB.Net example, written by a slew of mechanical engineers.
CodeSOD: A Poorly Pruned Branch
Juliano had this very non-WTF bit of PHP code:
CodeSOD: Many Unhappy Returns
Gavin continues work on the old C++ app he inherited. Today we get a delightful smattering of bad choices.
CodeSOD: Accessed Nulls
"The attached class connects to an Access database," writes Nicolai. That's always a good start for a WTF. Let's take a look.
Error'd: Left Hand Right
Tim Y. is on Fire with this burn."Competing teams inside Google? Or just the AI recognizing marketing tactics?"
CodeSOD: Reflect on Your Mistakes
While Java didn't invent putting a toString method in the base class of every object, it certainly made it mainstream. The nice thing about the method is that it allows you to turn any object into a string, though it's up to the implementor to decide what a good string representation is. But what if you want to ensure that the object you're handed is really and truly a string, not just something you can convert to a string?teknopaul's co-worker found their own solution:
Coded Smorgasbord: Minimal Commentary
Comments explain a lot about our code. And sometimes, the comments explain more than the code itself.Alastair found this lovely comment, which demonstrates an excellent, if confusing, understanding of a boolean "or":
CodeSOD: Suspicious Contents
While poring through some VB .Net code, John noticed some odd things in their datamodel. For example, a different process would scan files, and log any "suspicious" files into a database. The program John supported would then report on that data.One of their classes had a property which looked like this:
CodeSOD: Spaced Out Replacement
You have some text, and need to replace every sequence of spaces with a single space. E.g., My text becomes My text. Now, if you're most of us, you ignore the famous quote and reach straight for regexes.But Samuel's co-worker isn't most of us.
Error'd: Testing 1,2,3,4,5
An anonymous friend sent us our frist test in prod for this week. And then there will be more, and more, and more."This came up in Kaspersky's Blog's RSS. If you're luckythey might still have the error up in the original URL."I don't know if "chron" is just how "cron" translates to Russian and back, but the test appears to have succeeded.
CodeSOD: Totally Valid
Greg's co-worker really wanted to make sure that a variable was correctly set to true or false. So they did this:
CodeSOD: Metaception
Meta-programming- programs which generate programs- is a delightful hobby, but usually shouldn't be used in production code. Usually. I mean, if you're working in LISP, 90% of your program is going to be macros.But if you're using PHP and JavaScript, there's good odds that someone you work with has decided to combine these two tastes together to create something nobody wants to taste.This is a depressingly common anti-pattern, usually seen in the form of JavaScript code which looks like: if (1 == 2)- once upon a time one or both of those values were PHP variables, but we only see the resulting generated code.A more extreme version happened to our anonymous submitter.
CodeSOD: Finding the Right Size
Zeke sends us a C# snippet from an extract-transform-load process his company uses. It's... special.
CodeSOD: Article tF7q2
When I first saw Nick L's submission, I thought to myself, "This is just decompiled code, so of course the names are bad."
Error'd: Enterprising Michael
Faithful Michael R. is good for a chuckle today. "I am using the free tier Infura right now but think I will go enterprisey straight away."Can't turn down a deal like that, eh?
CodeSOD: Unaccountable Counting
Ulvhamne sends us some bad code that, well, I think at this point we should really coin a name for this particular anti-pattern.
CodeSOD: Query Query Query
Bob's employer had a data-driven application which wasn't performing terribly well. They had some in-house database administrators, but their skills were more "keep things running," and less "do deep optimizations". The company opted to hire a contract DBA to come in, address the performance problems, and leave.In actual fact, the DBA came in, ran some monitoring, and then simply wrote some guidance- generic, and frankly useless guidance. "Index on frequently queried fields," and "ensure database statistics are gathered on the appropriate schedule."The only meaningful output of the contractor's visit was a list of the badly performing stored procedures. Bob was given the list and told, "Go fix these."One stored procedure needed to populate variables with data from the order table. Specifically, it needed to collect sender_id, user_group, and file_ref from the orders table. Here's how it did that:
CodeSOD: An Obsolete Approach
Marcus's team was restructuring the API, and the architect thus wanted a number of methods marked obsolete, to encourage developers to move to the new version of the API. So the architect created a Jira task, assigned it to a dev, and moved on.Somehow, this C# code got committed and merged, despite being code reviewed:
CodeSOD: Concrapenate Strings
As oft discussed, null-terminated C-style strings are an endless source of problems. But there's no problem so bad that it can't be made worse by a sufficiently motivated developer.Today's rather old code comes from Mike, who inherited an old, MFC application. This code is responsible for opening a file dialog, and the key goal of the code is to configure the file filter in that dialog. In MFC, this is done by passing a delimited string containing a caption and a glob for filtering. E.g., "Text Files (.txt) | *.txt" would open a dialog for finding text files.
Error'd: Believe It Or Not
This week we have a special visit from a mythical beast: the snarklemma. But first, a non-error Error'd.Obsessive Optimizer Ian K."Walmart's nationwide network of warehouse stores meansthey can save time and money by shipping locally. FedExhas them covered: Their nationwide shipping fleet determinedthe shortest path from Houston to its largest suburb goes via Georgia."Not the shortest path, nor the fastest, but surely the cheapest one that meets the delivery date requirement. It's probably not an error, and I believe it, but I still can't believe it!
CodeSOD: A List of Mistakes
Yesterday we talked about bad CSS. Today, we're going to talk about bad HTML.Corey inherited a web page that, among other things, wanted to display a bulleted list of links. Now, you or I might reach for the ul element, which is for displaying bulleted lists. But we do not have the galaxy sized brains of this individual:
CodeSOD: Classical Design
There is a surprising amount of debate about how to use CSS classes. The correct side of this debate argues that we should use classes to describe what the content is, what role it serves in our UI; i.e., a section of a page displaying employee information might be classed employee. If we want the "name" field of an employee to have a red underline, we might write a rule like:
CodeSOD: A Small Partition
Once upon a time, I was tuning a database performance issue. The backing database was an Oracle database, and the key problem was simply that the data needed to be partitioned. Great, easy, I wrote up a change script, applied it to a test environment, gathered some metrics to prove that it had the effects we expected, and submitted a request to apply it to production.And the DBAs came down on me like a sledgehammer. Why? Well, according to our DBAs, the license we had with Oracle didn't let us use partitioning. The feature wasn't disabled in any way, but when an Oracle compliance check was performed, we'd get dinged and they'd charge us big bucks for having used the feature- and if we wanted to enable it, it'd cost us $10,000 a year, and no one was willing to pay that.Now, I have no idea how true this actually was. I have no reason to disbelieve the DBAs I was working with, but perhaps they were being overly cautious. But the result is that I had to manually partition the data into different tables. The good news was all the writes always went into the most recent table, almost all of the reads went to either the current table or last month's table, and everything else was basically legacy and while it might be used in a report, if it was slower than the pitch drop experiment, that was fine.It was stupid, and it sucked, but it wasn't the worst sin I'd ever committed.Which is why I have at least some sympathy for this stored procedure, found by Ayende.
CodeSOD: A Top Level Validator
As oft stated, the specification governing email addresses is complicated, and isn't really well suited for regular expressions. You can get there, but honestly, most applications can get away with checking for something that looks vaguely email like and call it a day.Now, as complicated as the "accurate" regex can get, we can certainly find worse regexes for validating emails. Morgan did, while on a contract.The client side had this lovely regex for validating emails:
Error'd: Paycheque
There are an infinite variety of ways to be wrong, but only very small number of ways to be right.PatientPeter W. discovers that MS Word is of two minds about English usage."Microsoft Word just can't seem to agree with itself on how to spell paycheck/pay check."Faithful readers know it's even worse than that.
CodeSOD: To Tell the Truth
So many languages eschew "truth" for "truthiness". Today, we're looking at PHP's approach.PHP automatically coerces types to a boolean with some fairly simple rules:
CodeSOD: Terminated By Nulls
Strings in C are a unique collection of mistakes. The biggest one is the idea of null termination. Null termination is not without its advantages: because you're using a single byte to mark the end of the string, you can have strings of arbitrary length. No need to track the size and worry if your size variable is big enough to hold the end of the string. No complicated data structures. Just "read till you find a 0 byte, and you know you're done."Of course, this is the root of a lot of evils. Malicious inputs that lack a null terminator, for example, are a common exploit. It's so dangerous that all of the str* functions have strn* versions, which allow you to pass sizes to ensure you don't overrun any buffers.Dmitri sends us a simple example of someone not quite fully understanding this.
Two Pizzas for ME
Gloria was a senior developer at IniMirage, a company that makes custom visualizations for their clients. Over a few years, IniMirage had grown to more than 100 people, but was still very much in startup mode. Because of that, Gloria tried to keep her teams sized for two pizzas. Thomas, the product manager, on the other hand, felt that the company was ready to make big moves, and could scale up the teams: more people could move products faster. And Thomas was her manager, so he was "setting direction."Gloria's elderly dog had spent the night at the emergency vet, and the company hadn't grown up to "giving sick days" yet, so she was nursing a headache from lack of sleep, when Thomas tried to initiate a Slack huddle. He had a habit of pushing the "Huddle" button any time the mood struct, without rhyme or reason.She put on her headphones and accepted the call. "It's Gloria. Can you hear me?" She checked her mic, and repeated the check. She waited a minute before hanging up and getting back to work.About five minutes later, Thomas called again."Hey, did you call me like 10 minutes ago?""No, you called me." Gloria facepalmed and took a deep, calming breath. "I couldn't hear you."Thomas said, "Huh, okay. Anyway, is that demo ready for today?"Thomas loved making schedules. He usually used Excel. There was just one problem: he rarely shared them, and he rarely read them after making them. Gloria had nothing on her calendar. "What demo?""Oh, Dylan said he was ready for a demo. So I scheduled it with Jack."Jack was the CEO. Dylan was one of Gloria's peers. Gloria checked Github, and said, "Well, Dylan hasn't pushed anything for... months. I haven't heard anything from him. Has he showed you this demo?"Gloria heard crunching. Thomas was munching on some chips. She heard him typing. After a minute, she said, "Thomas?""Oh, sorry, I was distracted."Clearly. "Okay, I think we should cancel this meeting. I've seen this before, and with a bad demo, we could lose buy in."Thomas said, "No, no, it'll be fine."Gloria said, "Okay, well, let me know how that demo goes." She left the call and went back to work, thinking that it'd be Thomas's funeral. A few minutes before the meeting, her inbox dinged. She was now invited to the demo.She joined the meeting, only to learn that Dylan was out sick and couldn't make the meeting. She spent the time giving project updates on her work, instead of demos, which is what the CEO actually wanted anyway. The meeting ended and everyone was happy- everyone but Gloria.Gloria wrote an email to the CEO, expressing her concerns. Thomas was inattentive, incommunicative, and had left her alone to manage the team. She felt that she was doing more of the product management work than Thomas was. Jack replied that he appreciated her concerns, but that Thomas was growing into the position.Julia, one of the other product managers, popped by Gloria's desk a few weeks later. "You know Dylan?"Gloria said, "Well, I know he hasn't push any code in a literal year and keeps getting sick. I think I've pushed more code to his project than he has, and I'm not on it."Julia laughed. "Well, he's been fired, but not for that."Thomas had been pushing for more demos. Which meant he pulled Dylan into more meetings with the CEO. Jack was a "face time" person, and required everyone to turn on their webcams during meetings. It didn't take very many meetings to discover that Dylan was an entirely different person each time. There were multiple Dylans."But even without that, HR was going to fire him for not showing up to work," Julia said."But... if there were multiple people... why couldn't someone show up?" Gloria realized she was asking the wrong question. "How did Thomas never realize it?"And if he was multiple people, how could he never get any work done? Dylan was a two-pizza team all by himself.After the Dylan debacle, Thomas resigned suddenly and left to work at a competitor. A new product manager, Penny, came on board, and was organized, communicative, and attentive. Gloria never heard about Dylan again, and Penny kept the team sizes small. [Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
CodeSOD: They Key To Dictionaries
It's incredibly common to convert objects to dictionaries/maps and back, for all sorts of reasons. Jeff's co-worker was tasked with taking a dictionary which contained three keys, "mail", "telephonenumber", and "facsimiletelephonenumber" into an object representing a contact. This was their solution:
...234567891011...