Feed the-daily-wtf The Daily WTF

Favorite IconThe Daily WTF

Link http://thedailywtf.com/
Feed http://syndication.thedailywtf.com/TheDailyWtf
Updated 2024-11-21 11:31
CodeSOD: Plugin Acrobatics
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.
CodeSOD: Recursive Search
Sometimes, there's code so bad you simply know it's unused and never called. Bernard sends us one such method, in Java:
CodeSOD: Objectified
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:
Error'd: Tangled Up In Blue
...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."
CodeSOD: Secondary Waits
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?
CodeSOD: The First 10,000
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:
Representative Line: How is an Array like a Banana?
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:
CodeSOD: Pay for this Later
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.
Error'd: Relatively Speaking
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?"
Representative Line: One More Parameter, Bro
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:
CodeSOD: Uniquely Validated
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.
CodeSOD: Counting it All
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:
CodeSOD: A Matter of Understanding
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".
Error'd: Alternative Maths
"Check out Visual Studio optimizing their rating system toonly include the ratings used," sharedFiorenzo R. Imagine the performance gain!
CodeSOD: All the Rest Have 31
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.
CodeSOD: A Base Nature
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.
Representative Line: On the Log, Forever
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.
CodeSOD: Trophy Bug Hunting
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:
Error'd: What Goes Around
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."
CodeSOD: Join Our Naming
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.
CodeSOD: Querieous Strings
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.
Coded Smorgasbord: What the Hmm?
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:
CodeSOD: Perfect Test Coverage
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.
Error'd: Friday On My Mind
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.
CodeSOD: Ancestry Dot Dumb
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:
CodeSOD: Time to Change
Dennis found this little nugget in an application he inherited.
CodeSOD: An Overloaded Developer
"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?"
Representative Line: Ripping Away the Mask
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:
Error'd: You Don't Need A Weatherman
...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!"
CodeSOD: Idtoic Mistakes
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:
CodeSOD: JaphpaScript
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.
CodeSOD: A Cache Exists
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.
Representative Line: Try to Catch This
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:
Error'd: Stop Poking Me!
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)!"
CodeSOD: Library Checkout
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:
CodeSOD: Join or Die
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:
CodeSOD: Feeling Free
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:
CodeSOD: Switch How We Do Padding
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.
Error'd: Operation Erred Successfully
"Clouds obscure the result," reportsMike T.'s eight-ball."It's a shame when the cloud and the browser disagree," he observed.
CodeSOD: True Parseimony
We've seen this pattern many times here:
Space for Queries
Maria was hired as a consultant by a large financial institution. The institution had a large pile of ETL scripts, reports, analytics dashboards, and the like, which needed to be supported. The challenge is that everyone who wasn't a developer had built the system. Due to the vagaries of internal billing, hiring IT staff to do the work would have put it under a charge code which would have drained the wrong budget, so they just did their best.The quality of the system wasn't particularly good, and it required a lot of manual support to actually ensure that it kept working. It was several hundred tables, with no referential integrity constraints on them, no validation rules, no concept of normalization (or de-normalization- it was strictly abnormalied tables) and mostly stringly typed data. It all sat in an MS SQL Server, and required daily manual runs of stored procedures to actually function.Maria spent a lot of time exploring the data, trying to understand the various scripts, stored procedures, manual processes, and just the layout of the data. As part of this, she ran SELECT queries directly from the SQL Server Management Studio (SSMS), based on the various ETL and reporting jobs.One reporting step queried the "BusinessValue" column from a table. So Maria wrote a query that was similar, trying to understand the data in that column:
CodeSOD: Secure Cryptography
Governments have a difficult relationship with cryptography. Certainly, they benefit from having secure, reliable and fast encryption. Arguably, their citizens also benefit- I would argue that being able to, say, handle online banking transactions securely is a net positive. But it creates a prisoner's dilemma: malicious individuals may conceal their activity behind encryption. From the perspective of a state authority, this is bad.Thus, you get the regular calls for a cryptosystem which allows secure communications but also allows the state to snoop on those messages. Of course, if you intentionally weaken a cryptographic system so that some people can bypass it, you've created a system which anyone can bypass. You can't have secure encryption which also allows snooping, any more than you can have an even prime number larger than two.This leaves us in a situation where mathematicians and cryptography experts are shouting, "This isn't possible!" and cops and politicians are shouting "JUST NERD HARDER!" back.Well, today's anonymous submitter found a crypto library which promises to allow secure communications and allow nation states to break that encryption. They've nerded harder! Let's take a look at some of their C code.
Tales from the Interview: Cleaning House
Craig had been an IT manager at an immigration services company for several years, but was ready to move on. And for good reason- Craig had suffered his share of moronic helldesk nonsense and was ready to let someone else deal with it. This meant participating in interviews for his replacement.Craig had given a rather generous three months notice, and very quickly the remaining three months were taken up with interviewing possible replacements. Each interview followed the same basic pattern: Craig would greet the candidate, escort them down to the fish-bowl style conference room in the center of the office, where a panel of interviewers ran through a mix of behavioral and technical questions. The interviews were consistently disappointing, and so they'd move on to the next candidate, hoping for an improvement.After the first few interviews, he started making up questions about potentially horrible IT related disasters. "You see an executive using scissors to cut the Ethernet cable. When pressed, they explain that they want their connection to be wireless. What do you do?" "It's the holiday season, and you see someone trying to extend Christmas lights in the break room using a suicide cable, what do you do?" "You discover one of the technicians has been hiding a bottle of whiskey in the server room. What do you do?"This kept Craig entertained, but didn't get them any closer to hiring any of these candidates.One day, they brought in another candidate, and Craig ran the standard interview. His mind wasn't really on the interview- the candidate's resume wasn't the best they'd seen, and it took only a few minutes to establish that they probably weren't the best fit for the role. So Craig spent the time thinking more about whatever absurd question he was going to ask than what was going on in front of him.His mind drifted off, and his eyes wandered around the office. They strayed to the corner office, also fishbowl style, where the CEO sat. And that's when Craig realized he wasn't going to need to make anything up for today's interview."What would you do if you saw a member of staff washing their keyboard with Evian mineral water, while sitting at their desk, their computer still on and keyboard still plugged in?"The candidate was bemused, and just sat silently. For a long beat, they just watched Craig. Craig, obligingly, pointed back to the CEO's office, where the CEO was in the process of doing exactly what Craig had described.The candidate took in the scene. Saw the placard announcing that as the CEO's office. Saw not just one, but two open bottles of Evian. Saw the water spreading everywhere, as the CEO hadn't considered things like "have some paper towels on hand".The candidate turned back to Craig, and eloquently shrugged. There was a world-weariness in the shrug, that spoke to long experience with situations like this. It was the shrug of an IT manager that was going to keep a healthy stock of replacement keyboards, and never ever let the CEO have a laptop.In the end, it was that candidate who got the job, not because they had the best interview, or the best resume, but because they knew what they were getting in to, and were ready to deal with it.The keyboard, however, wasn't so lucky. "How else was I supposed to get the breadcrumbs out of it?" the CEO asked while Craig replaced the keyboard.[Advertisement] Picking up NuGet is easy. Getting good at it takes time. ProGet costs less than half of Artifactory and is just as good. Our easy-to-read comparison page lays out the editions, features, and pricing of the different editions of ProGet and Artifactory.Learn More.
Error'd: A Dark Turn
You may call it equity, or equinox or whatever woketerm you like but you can't sugarcoat what those of us in the North know:the Southern Hemisphere is stealing the very essence of our dwindlingdays. Sucking out the insolation like a milkshake and slurping it allacross the equator.
CodeSOD: A Managed Session
Some time ago, Roald started an internship on a ASP .Net application. It didn't take long to find some "special" code.
CodeSOD: String in your Colon
Anders sends us an example which isn't precisely a WTF. It's just C handling C strings. Which, I guess, when I say it that way, is a WTF.
CodeSOD: String Du Jour
It's not brought up frequently, but a "CodeSOD" is a "Code Sample of the Day". Martin brings us this function, entitled StringOfToday. It's in VB.Net, which, as we all know, has date formatting functions built in.
CodeSOD: A Clever Base
Mark worked with the kind of programmer who understood the nuances and flexibility of PHP on a level like none other. This programmer also wanted to use all of those features.This resulted in the Base class, from which all other classes descend.Mark, for example, was trying to understand how the status field on a Widget got set. So, he pulled up the Widget code:
Error'd: Nothing Doing
Two this week from our old friend Michael R., or maybe it's one.This week, Michael tells us "I am sure I am running some applications but it seemsI am not and those not running have allocated all the memory."
CodeSOD: Switching the Order
Let's say you had 6 different labels to display. There are many, many ways to solve this problem. Most of them are fine. Some of them are the dreaded loop-switch anti-pattern.Julien unfortunately inherited one of those.
12345678910...