Feed the-daily-wtf The Daily WTF

Favorite IconThe Daily WTF

Link http://thedailywtf.com/
Feed http://syndication.thedailywtf.com/TheDailyWtf
Updated 2024-11-23 08:46
CodeSOD: All Wrapped Up
PHP has a lot of warts, and one of those warts is its approach to database interactions. If you want to talk to a MySQL database, every function for doing it is prefixed mysql_, and for say, Postgres, you’d use functions prefixed pg_. On the other hand, it uses an object oriented approach for talking to SQLite3, while Oracle not only has a set of oci_ prefixed functions, but has to add a bunch of important functions that make it just different enough as to be difficult to switch to.It’s a bit of a mess, is the point, and the result is that a lot of developers will write some wrapper functions to make it easier to write generic code that’s not tied to a specific database engine. That is, presumably, what Scott’s co-worker had in mind when building this library of wrapper functions:
Error'd: In Memoriam
"I went to get my stuff off the printer at work but it appeared to have passed," writes Kelly B..
Featurette: Puppet Labs
As we announced a few months back, Puppet Labs is one of our sponsors. As part of that arrangement, I got to go behind the scenes and learn a little bit about how things work at Puppet Labs.I got to have a conversation with Stephanie Stouck, a product marketing manager, as well as Eric Sorensen, their technical product manager. Eric’s a long-time sysadmin who migrated from being a customer of Puppet and its competitors into being someone who makes Puppet. Stephanie comes from a background in product marketing, but gets to see how customers are using Puppet.Before we get into that, though, let’s get the important question out of the way. Puppet Labs is based in Portland. How’s the office coffee? “Delicious!” according to Stephanie. “We have a kind of ridiculous coffee culture,” Eric says. “I feel at least partially responsible.” He should- he’s the star of Puppet’s internal training video on how to care for their espresso machine.Puppet is one of the big products at the center of the “DevOps” space. DevOps, like “the cloud”, and “agile”, is a term everyone uses, but no one can accurately define. I gave Stephanie and Eric a chance to nail the term down.“DevOps is as much a cultural shift,” Stephanie explains, “as it is a set of work practices.” It’s not a specific set of tools, techniques, or practices, but more a goal: “DevOps means development and operations teams are aligned around a single business goal- to deliver value to customers.”Eric expands on that alignment. “It’s sharing technology that’s taken for granted on one side of the dev/ops divide and implementing it in a new way… for example, bringing pervasive version control and CI from the dev world and applying it to infrastructure code; conversely, taking the idea of monitoring every metric and instrumenting the application to expose those metrics from day one.”This all feels very warm and fuzzy, but let’s get down to brass tacks. I don’t want to end up being the subject of an article on TDWTF. How does Puppet help with that? Eric has a strong opinion:
CodeSOD: Circle Space
Self Service
Anna’s employer made billing software for energy companies, and they had just entered into an exciting time: the Dutch utility market was loosening its regulations, and that meant a flood of startups were looking for a cheap way to bill their customers. Of course, their product was designed for the US market, not the Dutch market, but the CEO didn’t see that as a problem. “No worries,” he would say, “Anna’s our top notch configurator, and she’ll customize it for you in no time.”This, of course, was news to Anna, who didn’t actually know anything about the configuration of the software. After a one-day training session, she was officially declared the “expert”, and sent off to sink or swim- and she mostly swam. There were a lot of options in the package, and it was extensible through add-ons, which meant Anna spent a lot of time whipping together one-off modules for each customer’s deployment.During this period, one of her “favorite” customers was Joep. Joep had needs. Joep had a lot of needs. He was polite, and friendly, and Anna liked Joep, but Joep tended to start every conversation with, “You know, it’d be nice if…” and then invent a thousand new requirements for the billing package.A lot of them were around reporting, which was not the system’s strong suit. Joep wanted the ability to run ad hoc reports against any dataset his mind could imagine. “How many left-handed customers logged into the billing application between 2:04AM and 2:37AM and were also watching something on Youtube?”This lead to a lot of screen-sharing sessions and on one of those calls, Anna fired up Toad to connect to the back end database.“Oh! What’s that?” Joep asked, as she typed in a query.“I’m just trying to see if we’ve got the data we’d need to build your report.”“And you can type commands… to build custom queries?”“Yes…” And Anna was seduced by temptation. Joep wanted a lot of custom reports, and if she showed him how to use Toad and introduced him to basic SELECT statements, he’d be able to “self service”, and that would save her a lot of headaches. So Anna helped him install Toad, disable the auto-commit functionality, and showed him how to write SELECT statements. Joep was happy, and Anna fielded far fewer calls from him.Time passed. Anna moved on to work with other customers, Joep changed jobs, and roughly a year later, their paths crossed again. Anna’s latest client was Joep’s new employer. They shared a laugh, reminisced about old times, and then talked about Joep’s new needs.This time, they had a SQL Server back-end, which didn’t really change much about how the billing package worked. Anna noted that, and started gathering requirements for the new batch of add-ons and custom screens she’d need to build. While she was concentrating on that, Joep asked, “I was looking at SQL Server, and Microsoft’s management tools look even nicer than Toad. Do you think I could use those?”“Sure, I guess,” Anna said, without really thinking about it. Over the next few weeks, she got Joep’s new company set up and configured to their liking, and moved on to the next client.Months later, this email arrived:
CodeSOD: Bonus WTF: Happy Birthday, George Boole
Today is George Boole's 200th Birthday. We've rerun this classic many times, but I can't think of a better time to reshare it! - RemyThe problem with "logic" is that it makes things out to be nothing but simple dualities. Proponents of logic want us to believe that everything is true or false, black or white, yes or no, paper or plastic, etc. Thankfully, there are some among us, like Mark Harrison's colleague, who are not afraid to stand up to these logic advocates and shout "no, I will not succumb to your false dichotomies!" Today, I think we all should salute those few brave people ...
CodeSOD: Shadow Over XML
Halloween may be over, but it’s always a good time for a horror story.Like many horror stories, Nick’s starts with a mysterious inheritance from a long-gone predecessor. This tool manages student data, and it needs to pull data from documents in Microsoft Word XML, using C#.The escalation of any horror story moves in small increments. First, you notice things that are a little off, like this method signature:
Error'd: Schrödinger's Tortoise (SVN)
"It's curious that SVN is simultaneously both clean and unclean until the computer is restarted," Hesham M. wrote.
CodeSOD: Leading Development
H. J. works in a place where best practices are known, but bitterly opposed. You see, they have a lead developer who is more experienced than the rest, and it is his mission to show the others how things should best be done. Some of his finer resume-worthy accomplishments...
Tales from the Interview: Monitoring the Situation
Joe T recently decided it was time to go job hunting. This mostly meant deflecting emails from head-hunters, doing phone interviews with ignorant HR departments, and the occasional on-site interview with a possible employer. One of those on-site interviews brought him to an IT services company which handled a few large US government contracts.The building itself was buried way in the back of a tech park, behind a small pond inhabited by ducks and migrating geese. It was modern, in a circa 2002 way, gleaming white, with a large and mostly empty parking lot, and a glossy lobby and a pair of cheerful receptionists.One of the receptionists made a call. A few moments later, Ricky, Joe’s contact, stumbled out of the elevator. He had the look of a man who hadn’t slept in a month. As they piled into the elevator, he said, “We are really eager to fill this position. Just between you and me, I think you’ve got it sewn up, but you need to meet the team.”Ricky led him into a conference room, where a few other sleep-deprived looking techs nursed their coffees. After a round of handshakes, they dove into a series of sysadmin/operations questions. Some of them were just dumb trivia: “What’s the purpose of the -i flag on the ls command?” Some were dumb soft-balls: “What time management techniques do you use?”After the warmup, Ricky leaned forward, and got right to the meat of it. “You’ve got three data centers,” he said, “how would you monitor all three of them?”That was a vague question, so Joe could only give a vague reply. “Well, I’d imagine all three are connected to the same management network. So I’d run some sort of monitoring package on that network.”“You don’t have that,” Ricky said. Joe couldn’t be sure, but he thought he might have seen a grimace on the face of one of the techs.“Well,” Joe said, “then we’d just have to set up monitoring in each DC independently, and then aggregate somehow, but that’s really not the best option. Setting up a management network is-”“Ah,” Ricky interrupted, “but what if you don’t have the budget for any monitoring software?”Joe, sitting in the middle of the interview, jumped to a conclusion about Ricky’s line of questioning. This was one of those old interview tactics: no matter how the candidate replies, throw up an obstacle, and see how they can “think outside the box”. This was just a bizarre hypothetical situation. He played along. “I guess we’d need to install Nagios or some other open source monitoring tool.”“The customer doesn’t allow any open source software on the network,” Ricky countered.“None?” Joe asked. “But don’t you have some Linux servers?”Ricky nodded. “We do. But no open source software on the network.”“Well, I mean, if you can’t buy software, and you can’t use free software, you can’t really do any meaningful monitoring.”Now Joe was certain: the techs were all grimacing, and oh so very slightly nodding along with him. This was what they expected him to say, but Ricky wasn’t going to give in yet. “Now, you can’t just throw your hands up and say, ‘It can’t be done.’ You have to monitor these datacenters, so what do you do?”“Well… I mean, at that point, we’re just writing our own scripts and running cron jobs. But that’s a totally ridiculous scenario. No one would actually run a datacenter that way!” Joe punctuated the statement with a laugh, because obviously this was all just silly.No one else laughed. Ricky’s line of questioning wasn’t a hypothetical, it was an accurate description of their infrastructure in their datacenters. After a solid minute of awkward silence, Ricky started asking questions about the previous jobs on Joe’s resume.Somehow, Joe left the interview with a job offer, but he politely declined.[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!
CodeSOD: The Hard Problem
I’ll warn you to start: this is a date handling CodeSOD, but that’s only a small part of the WTF. You see, there’s an old joke, “There are three hard problems in computer science: naming things and counting things.” This code has a hard time with the first:
Just Following Instructions
Cameron was a support rep for a Unix-based software package that had also been ported to Windows and Mac OS X. He supported every version, and quickly learned that not all ports were created equal.The Windows port was the angel of the pair. The developers had written an installer with NSIS that created an icon on the Desktop for users to double-click. It worked well enough that Cameron almost never fielded Windows install support tickets.The Mac port was the devil from a support standpoint, and there was really no good reason for it. As long as Xcode and X11 were installed on the user's machine, everything worked perfectly. However, few Mac users had these libraries out of the box.No problem. On their product download webpage, they supplied links not just to their own installer, but also for the Xcode and X11 installers. And yet, the number of users calling in to flail helplessly were numerous."What link? I don't see it anywhere!""The installer's on another site?""What do I do now?"When Cameron walked users through the process verbally, it always went fine. He got so much practice at it that the instructions were practically encoded into his neurons.One day, Cameron had a sanity-preserving idea. He ran it past his boss, who then set up a meeting with the product website masters."We field a ton of calls for this Xcode and X11 install stuff," Cameron explained. "No one can figure it out without some help. I'd like to set up a webpage describing the whole install process step-by-step. I think it'll really cut down on the confusion. I know HTML, I can put the page together myself with screenshots and everything."Everyone agreed it was a good idea. After some minor negotiating, the web team agreed to give Cameron access to the product website's test domain. "Write up the page you want. Once you get it how you want it, we'll QA it, then promote it," they told him.The opportunity to do something outside the same old support work was exciting to Cameron. His HTML experience came from all the personal websites he'd thrown together since the days of Geocities, and wasn't too shabby. He put together a nice step-by-step breakdown, describing every detail of going to the appropriate external website and running the installers, with screenshots and links to everything the users would need. In the screenshots, he painstakingly indicated each button and link to click with little circles and arrows.His boss liked the page, praising his "moron-proof," thorough instructions. The page went live soon after. Cameron looked forward to spending more time on more challenging support tasks.A few months later, he resigned himself to the bitter reality that nothing had changed. It seemed no one on the planet could perform the Mac install unassisted. He fielded calls from end users all the way up to "network administrators" and "tech professionals.""It doesn't work for me! Nothing happens when I click the links!""I followed your instructions to the letter, but the icons didn't work.""Nothing happened."Strangely, each time Cameron walked someone through the process, everything went fine. He couldn't understand it.Neither could his boss, who wanted to reduce this pain point for his support staff. He approached Cameron one day with a suggestion. "Hey, we're doing a trial of this new remote viewing tool. It'll let us see exactly what users are doing, and dig into their systems directly if we have to. Would you like to try using it to see what the deal is with these Mac installs?""Sure!" Cameron was willing to try anything.It didn't take long for another call to test on. "When I click the icon, nothing happens," the user explained to Cameron."All right." Annoying, but old hat by that point. "I'm gonna email you a link to a remote viewing session. This'll let me watch your install process. Can you click that link when you get it?""Sure."They were connected a few moments later. The man's kitten-festooned desktop filled Cameron's view."OK, can you go to your browser and walk me through what you're trying to do?" Cameron asked."OK." The user opened up a new browser window and clicked a bookmark in the toolbar. "First, I go to your product page."It loaded obediently a few moments later."I go to the instruction page …" He clicked the link to Cameron's how-to page. "Scroll down here a bit … then I click this icon, and nothing happens."Cameron looked on in mute horror as the user furiously clicked a screenshot displaying the X11 icon with a circle around it. The 3x3-inch screenshot that he'd been careful to label "Screen Shot" in big letters."Oh. Uh …" Are you kidding me? This is what everyone's doing?! Cameron took a deep, calming breath before continuing. "That's not where you want to be clicking. Just a little higher than that is a link that says ‘Click here to open the Xcode install page in a new window.' Can you try that one?""OK." The user complied, and the Xcode site loaded obediently."There we go!"Cameron had no trouble walking the user through the rest of the process. Afterward, he sat back with a frown, thinking. Should he remove the screenshots? No, they were important for illustrating what to do on the Xcode and X11 websites. There was a better way to handle this, he was certain.He took to Google. After a little research on Javascript onclick events, he contacted the web maintenance team, describing the change he wanted to make.Sure! they emailed back. Do it in test and tell us when you're done.From there, Cameron added a script to his webpage so that whenever someone clicked on any screenshot, a window popped up that read, "You are clicking on a screenshot within our instructions. In the Xcode/X11 website, find the window that resembles the screenshot and click on the icon there."[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!
Error'd: Google's Time Travel Shenanigans
"10 minutes is pretty reasonable, but I don't think that I'm going to make my connection 2 minutes in the past," writes Rich H.
CodeSOD: A Well Mapped Error
Marvin’s company had a problem. Their C++ application tended to throw out a lot of error codes. That was actually okay- that application had a lot of possible failure modes that it couldn’t do anything about other than cough up an error and quit.The problem was that their customers weren’t particularly happy with messages like: Error: QB57, since it told them absolutely nothing. “RTFM” was not an acceptable response, so someone had to add some functionality to turn those cryptic error codes into meaningful messages.Since it was a simple job, they handed it off to the co-worker who nobody really thought all that much of. He was a terrible programmer, but how badly could he screw a simple map/hash/dictionary problem up?First, construct the data structures to hold the error messages:
Apache Chief
W.T.F. Community College hired a team of highly-recommended web design consultants to bring its website in to the 21st century. Paul was tasked with overseeing their work and supporting the new site upon go-live. After a couple months of grinding, they cranked out a beautiful new site that was accessible, navigable, and responsive. It also removed the old site's dependence on Flash, replacing it with a titanic mound of PHP and JavaScript that was run by Apache. Paul and his team gave it a thorough beating in their test environment and everything seemed solid. They even gave a demo of it to the the head of W.T.F. Community College, President Skroob. He was able to easily find his way around, sign up, set his password to 1-2-3-4-5, and register for fake classes. It got the Prez's official salute of approval. The amazing new website was ready to be launched in time for the fall semester.The first day of classes rolled around and suddenly everything didn't seem so rosy. President Skroob frantically burst in to the IT office shouting "The web site is down! The web site is down!" A quick check of the monitoring system didn't show anything wrong, and manual inspection didn't either. The server hosting the site was hardly breaking a sweat. No pressure on CPU, RAM, or I/O. Paul tried browsing to the site and the browser just hung. No errors, no nothing."Well that's interesting," Paul said to no one in particular. "We've lost the bleeps, the sweeps, and the creeps.""Why don't we try restarting Apache?" one of Paul's cohorts suggested. Paul shrugged and did so, and the website immediately returned to normal."I don't know what old Indian tribes have to do with our web site, but I'm glad it's working now!" President Skroob stated before ducking out of the office.Paul set up a simple monitor to hit the home page every 5 minutes to make sure the problem didn't return. But an hour later, the alarm went off. He restarted Apache quickly, and things cleared up. So began a nightmare where someone from Paul's team always had to be available to restart Apache once the website hung. The Prez was not pleased."Get a hold of the Apache Chief who made this website and get them in here to fix it NOW!" Skroob shouted at Paul.Paul got on the horn to the consultants, who hemmed and hawed about checking their code. If they were to be brought back in, it would cost W.T.F. CC an exorbitant sum. Paul decided to look more closely at the server first, and found Apache was running out of processes. He increased the MaxProcesses limit which bought them some time before the site would hang again. All processes were stuck in CLOSE_WAIT status, meaning the client browser had closed the connection but the server hadn't.A system call trace on a stuck server process showed it was waiting on a file lock, and a stack dump showed the culprit was `mod_php`. Since they were waiting on a lock, they were suspended and couldn't exit. In fact, all the dozens of stuck processes were waiting on the same file: `/var/lib/php/session/sess_111`.Paul got back on the phone with the consultant team and learned the story behind this big WTF. The new website had feeds (such as current events and the faculty directory) that could be updated dynamically and might be accessed from any session. But to avoid regenerating the output HTML on each load, it was cached so every PHP process could get to it. The consultants had done this using a single, global, monster PHP session.Thus, every website hit required a server process to read and write that one session, thus locking the session file. If new requests came in at Ludicrous Speed, they were unable to get through the bottleneck and eventually Apache couldn't spawn any more processes. At that point, the site would go catatonic to the user."Guys, this is in no way acceptable," Paul berated Apache Chief & Co. "You need to find another approach to caching the data." Meanwhile, Paul wrote a workaround script that ran once a minute and restarted Apache if there were too many stuck processes. Two weeks and thousands of dollars later, the consultants ameliorated the problem by dividing traffic amongst four different cache "sessions".It worked well enough that Paul's script only got triggered during extremely high usage times. Even then, there was very little downtime. President Skroob put the kibosh on any more of the school's Space Bucks going to the Apache tribe, so getting them to develop something that wasn't just a hack job was out of the question. As long as it worked most of the time and kept Skroob out of their office, Paul was comfortable with leaving well-enough alone.[Advertisement] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too!
CodeSOD: Sort, Then Add, Forever
Go-live day for the new CabinetWorld redesign was a tense, hurried affair. Developers streamed in at 5:00 AM, hoping to catch wind of early problems before most of the country awoke and started shopping. True to form, the overworked break-room coffee machine gave up the ghost at 5:10, but luckily, at 6:00 the boss brought in doughnuts, and by 6:30 a Starbucks run had been arranged. Everyone huddled in the war room, nervously watching the monitors as the number of concurrent visitors rose steadily. And then ..."Why's it slowing?" Ashley whispered, not wanting to cause a panic.Dave stuffed the rest of a cruller into his mouth and looked where she was pointing: one particular API service was buckling under the so-far moderate load. Oddly enough, this wasn't part of the overhaul. This service, which merely returned a product list, was a legacy service they'd switched to using, one that powered their own internal tools. It should've been nice and stable—but instead, it chugged along like it had eaten a few too many doughnuts itself.Dave grabbed the source code while Ashley combed the production logs, looking for the source of the slowdown. "Crap," whispered Dave, noticing the version control history. "That's Bruce the Intern's work."Bruce had been the "clever" intern the summer he'd worked at CabinetWorld, the one they'd assigned actual coding tasks to. Unfortunately, he'd been too clever for his own good, as the code revealed:
An Efficient Curmudgeon
One of the things a good developer should always strive for is efficiency. Slow code should be improved if possible. Complicated steps should be simplified or removed. Finding a poorly-implemented process which is costing company time and streamlining it is usually a good thing, and means more profits, which means larger paychecks and bonuses, and happy bosses. Right?
Error'd: For Quality Assurance Purposes
"I don't work for them, so when did it become my job to do their quality control?" writes T. K.
CodeSOD: Validate My Feelings of Cleverness
It’s not uncommon to have a branch in your code along the lines of, if (debugMode) { doSomeLogTypeThingy(); }. Usually, we try and wrap that sort of stuff up and keep it far away from the actual business logic, and the result is a plethora of logging frameworks and diagnostic libraries.They are, however, consistent about one thing: whether or not debugMode is enabled or not, the actual business logic should behave the same way. They’re designed and intended to be minimally disruptive.Remco found this method:
Filing Data
Databases are wonderful things. They help you organize your data at multiple levels. Large logical units of data are stored in databases. Smaller logical divisions are stored in tables, and individual records are stored in rows. Once you have your data stored like that, you can access it in all sorts of wonderful ways.Of course, there's more to it than that. Beneath the database is the file system. Beneath that, there are one or more drive arrays each with one or more disk drives, each with one or more platters. Read/Write heads move back and forth to access the data on those platters. All sorts of sophisticated mechanisms have been developed to minimize the dead time of having a head in the right place, but waiting for the platter to spin the data beneath it for retrieval.DBAs take this into account when defining where the database and included tables will be stored. For example, they shouldn't put two databases (for different applications) that require extremely high rates of access on the same disks so as to minimize contention, because a head can't be in two places at once. Sometimes, they'll stripe data for a single table across multiple spindles so as to minimize hot spot activity by hashing the data across partitions.Mr. Anon. works with a DBA who believes that there is a better approach. Each database should contain one table. That database should reside in its own data file on the disk. Accordingly, there were thousands of data files. Since the operating system has a limit on the number of open file handles, the data server could only access so many databases at one time. The underlying theory was that this would reduce contention.However, since the files are stored all over the disks, the heads-can't-be-in-two-places-at-once issue still causes problems. Since a table/database is stored in a single file, it's no longer possible to stripe it (as one might with partitions). Also, since the data server can only open so many file handles at once, in order to open more, it must juggle opening and closing database file handles. As one might expect, this overhead is substantially noticeable.Of course, there is the maintenance side of things as well. Changing the log segment of a 200 table database is basically a one-off action. Doing it for a database that is stored as 200 separate databases of one table each now becomes a significant amount of effort. It's still O(n), where n is the number of databases, but now it's a huge effort. The same goes for every other database-level attribute.A more interesting facet is that now it's possible for only one table of your database to go down while all the others are happily processing requests. Now you need to code multi-table inserts as multi-phase commits.Equally interesting is how one might code a join of n tables, when it's possible that zero or more of them might be in databases that are unavailable. Hmm?All of this was rationalized as acceptable because it was all to support a web application, where performance didn't matter.Ah well, at least this way you know you'll never find a database with thousands of tables in it.[Advertisement] Release!is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!
Coded Smorgasbord: A Type of Insanity
Types are fundamental to most programming languages. Even the loosest, duckiest type system is still a system of some kind. It’s impossible to be a programmer if you don’t at least have a vague understanding of what types are, what they mean, and how you use them.Well, not impossible.The Null TypeKelly came across some C# code that needed to take the value in one variable (which may be null), and store it in the property in an object. Instead of writing the obvious statement:
Run Crash Crash Run
As Max entered the room, he was instantly greeted by a scorching wave of heat.As it turned out, even the freezing Russian weather was no match for the boiling hot atmosphere at Sturmovik Games' office. The small Moscow-based company with a humble portfolio of mobile games was just days away from a major content update for one of them. Naturally, the whole place was on red alert. Said update had been in the works for over six months, and had been widely advertised as the greatest overhaul the three year-old game had ever seen.During those six months, Max and his two coworkers put in an insane amount of work, implementing the ever-changing feature requests, writing and rewriting swathes of code, and fighting against the buggy third-party libraries they had to use. Finally, the stress and overtime hours were about to pay off. Every deadline had been met. All they had to do was deploy the update.Or so Max thought. The booming voice behind him brought him back to harsh reality."Who broke the build?!"The dreaded question hung in the air. Max turned to find Ivan, his fellow developer, standing and looking around the room to find the culprit. With the third developer on sick leave, there weren't many other people to whom the question could be addressed."What do you mean?" Max asked. "It worked yesterday, and ..." He trailed off when he noticed an email that had just arrived in his mailbox:
Error'd: Installing Flash Player is Hard Work
"Installing Flash Player sure is hard work," Mike H. wrote, "good thing that Adobe suggested taking a bit of a break afterwards."
Announcements: Sponsor Announcement: Scout
Our sponsorship program has been a great success, and we’ve got another great sponsor to help us keep this site running and bring you the horrors that your jaded eyes crave, along with special features like TDWTF Live and our recent BYOC contest about the Lucky Deuce. Our newest sponsor is Scout. They donate $10 to the Larimer County Humane Society every time somebody tries out Scout, and now they’re launching a new tool…Founded in 2009, Scout has been delivering SaaS based server monitoring software for over 6 years. With StatsD & AWS support, Scout Server Monitoring has been the clean, reliable alternative to expensive build-your-own monitoring solutions.Now, due to overwhelming customer demand for a fresh approach to APM, Scout has built a cloud-based / SaaS Application Performance Management tool for critical web applications. Dominant SaaS APM solutions (e.g. New Relic) are almost a decade old. Scout APM is a fresh take with modern, streamlined interface and unmatched capabilities.Scout APM provides deep metrics, analysis and solutions for performance problems in production web application. For developers, Scout APM is the fastest path from performance nightmares to the specific line-of-code. With built-in git integration, Scout APM can even identify the specific developer who can solve the problem based on code commit history.For managers and business owners, Scout APM prioritizes slow performance according to business impact. Scout APM allows customers to add context to find out who is affected most by slow performance.Find out more at: apm.scoutapp.com, or if you’re in Las Vegas for AWS re:Invent 2015 stop in at booth #1130. Be sure to ask about the Oculus Rift give-away[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!
CodeSOD: Not So Unique
When designing a database schema, it's often important to assign a unique identifier to each record. Such surrogate keys almost always make querying for data both simpler and faster, and the overhead of an additional column is usually a cost worth paying. As such, nearly all databases provide some means of generating such identifiers, either in form of sequential numbers, or more fancy UUID schemes.As is often the case at The Daily WTF, however, many developers prefer to reinvent the wheel. Today's code came to light when our Anonymous submitter—a mid-level programmer maintaining the codebase written by a team of senior developers and highly paid consultants—was tasked with investigating a failing bulk import from an external system. The procedure didn't throw any errors, but for some reason only half of the 12 million records ended up inserted into the database.Digging through the code, he finally found the source of all his problems:
Dual Helix
Bruce B., a recent high school graduate in need of a job, thought it was a good opportunity. A friend had set him up with a job at a one-man development shop. His new boss, Louis, would provide on-the-job training, and it paid well for an entry-level position.Louis met Bruce at the former’s house and led him to a basement office. “Your friend told me a lot about you, Bruce,” Louis said. He had a smile like Jack Torrance from The Shining. “Is it true you can already program?”“Oh, sure,” Bruce said. “I’ve been coding C# for a while now. I’ve learned how to use classes and interfaces–”“C#? What a useless language.” Louis waved his hand. “I’ve got the real deal.”Louis led Bruce an Apple LC. On the screen were displayed rounded rectangles, with labels such as “Unique” and “If/Then/Else”, linked together by arrows. It was as if someone had created a flowchart using children’s wooden letter blocks.“Helix,” Louis announced. “The pinnacle in computer programming languages.”A Normalized GenomeDouble Helix, Louis explained, was the most advanced version of a series of database management systems, using a fully-graphical programming language for its procedural code. Introduced early in the 1980s, Helix became a niche product by the end of the decade, overtaken by dbase and other, less GUI-reliant relational databases.“I’ll give you an ebook that will teach you the language,” Louis said. He stared longingly at the screen. “It’s truly a magnificent piece of software.”Bruce shook off the cultish feeling that afternoon before reading Louis’s email. He had attached a PDF of Riding the Helix Express. Bruce stayed up all night, reading it in morbid fascination.The next day he mentioned a passage on normalization to Louis. “The book doesn’t go into much detail. What do you use for normalization?”“What? Forget that.” Louis waved his arms around. “In fact, delete that book. It’s no good. Helix doesn’t need old-fashioned normalization. It has its own way of normalizing data.”Bruce didn’t remember that part from Riding the Helix Express, but Louis had already moved on. He put Bruce to work correcting some records in a car dealership’s database.Flowchart DNANone of the data, Bruce discovered, had been normalized. Salespeople would routinely mistype IDs and other fields, filling the database with mismatched data. In fact, there was no validation on any fields. As Bruce worked on other databases Louis had created, he found similar data integrity issues.Louis’s Helix code, which Bruce routinely had to troubleshoot, was worse. Those block-like flowcharts were much harder to follow than a regular, typed programming language, exacerbated by Louis’s spaghetti coding patterns. Fixing it was like untangling Christmas lights.But the money was good, so Bruce kept coming into work.Meanwhile, Louis showed growing disappointment in his new hire. “Bruce, I don’t know why I put up with you. You’re always critizing my work, you don’t follow my advice, and I’ve seen you reading that ebook I told you to delete. I really need you to shape up, or I’ll have to let you go.”Unwound HelixOne day, Bruce arrived in the basement to find Louis in a huff.“I’ve put up with your shenanigans all summer, Bruce. ‘Normalization,’ ‘indexing,’ it’s just one excuse after another with you!” He pointed at his screen. “Now, this procedure isn’t working. Show me you’re still capable of doing this job.”Bruce sighed, sat at his computer, and tried to make sense of Louis’s code. It was the worst tangle that he had seen since he started working for Louis. Worse, Bruce had skipped his coffee that morning, leaving him unable to concentrate.“I don’t think I–”“Gaaah!” Louis pushed Bruce aside and sat himself in front of the computer. He started playing with the blocks, teasing apart the code. Bruce, sitting nearby, watched in silence, listening to the clock ticking on the wall, the click-click of the mouse, Louis’s little groans of frustration. The Helix code swam in front of his eyes, filling the room, enveloping him–Bruce woke just before he hit the floor. He had fallen asleep and slipped out of his chair.Louis, caught up in his work, hadn’t even noticed.As his boss continued to untangle his own Helix code, Bruce quietly wrote a resignation note and left it on his desk. In his opinion, Double Helix should never have left the 1980s.[Advertisement] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too!
CodeSOD: The Most Pessimistic Search
Sometimes here at TDWTF, we get code snippets that are immediately obvious in their wrongness. But sometimes, the code only looks mildly inefficient, and it's up to the submitter to let us know how bad it actually is.Take the following snippet:
Eins, Zwei, Zuffa!
Dave had been at Initech for a few years, and things were looking pretty good. Everyone was working towards a big project launch, and every team was on target, on schedule, and on budget. The management, however, was not confident, and decided to “increase quality”. Their solution was to bring in two experienced, highly-paid consultants from the land of engineering excellence: Germany.The two consultants were Bob Schlüdell and Bob Gepäckträger. They became known as Bob Eins and Bob Zwei. They assessed the situation, then rolled up their sleeves and started hacking on all of the projects and code bases with their special skills.And how special those skills were.Bob Eins had two favorite things: C++ templates and threads. Anything that used both of these was good, and everything that did not was garbage and had to be rewritten to use threading and templates. He would take whatever library the company was using, reimplement about half of it with layer upon layer of templated classes, and inform the team that, “You will use this from now on!” Then he would start working on a new library and abandon the previous one, meaning that all of his code was unmaintained.Bob Zwei was a different kind of beast. At his previous job, he had worked on some project codenamed “Volcano”, and that was all he ever wanted to talk about. Ask him any question from, “Have you seen this compiler error before?” to “Hey, we’re all going out to lunch today, wanna come?”, and he’d respond with, “You know, back when I was working on Project Volcano…” followed by twenty minutes of chatter about design problems completely irrelevant to the initial topic of discussion.Dave managed to keep under the radar of the Bobs for awhile, but eventually they found him. They gave him a new core library to use. He sighed and went back to work. How bad could it be?It was much, much worse than he could possibly imagine. The first thing he learned was that these two Germans were very organized. Majorly, pedantically, obsessive-compulsively organized. Even the most uptight librarian would tell them to loosen up. Due to this, the Bobs demanded that everyone follow strict namespacing standards to keep code organized. However, each of the Bobs had their own radically different scheme.For example, a network socket class implemented by Bob Eins– because socket.h was Not Invented Here, and thus not good enough– was namespaced as base::universe::posix::network::socket::Constants::IPV4. It was unclear what existed outside of the base::universe namespace. Meanwhile, Bob Swei organized all his classes along the convention com::initech::divisionname::projectname::objectname, and refused to accept the reality that some projects spanned divisions, and thus couldn’t be slotted into that hierarchy.This was all somewhat manageable until Bob Eins dropped the biggest bomb. His NIH-itis flared up again, so he wrote his very own signal/slot mechanism. All existing code needed to be converted away from Qt’s perfectly usable mechanism as soon as possible. The unique feature of Bob’s version was that everything was a thread. Every service? Thread. Every operation? Thread. Every object? Thread. Every method call? Thread. Everything. This would, it was gloriously announced, get rid of the bottleneck of having a single event loop running on the main thread.Bob Eins answered every objection raised by the other developers with a variation of, “That is not an issue!” No reasoning was ever given. Future maintenance costs were “Not an issue!” Throwing away a year’s worth of working code was “Not an issue!” The massive amount of threading bugs, resource contention, and overhead were “Not an issue!”Bob Zwei answered every objection raised by the other developers with a variation of, “You know, back when I was working on Project Volcano…”All work ground to a halt. Because of the liberal use of templates, the project’s compile speed would have brought ridicule from a severely asthmatic snail. A “Hello World” for their framework took two minutes to compile. The full suite could take hours. Most developer time not wasted waiting for the compiler was spent adding mutexes everywhere, since you could no longer rely on any variable not magically changing out from under you. And the rest of their time was spent debugging race conditions, deadlocks, and resource leaks.Eventually, the Bobs stepped in with a new solution: every object in every thread would run its own personal event loop.Nothing was getting done, and management started getting anxious. One morning, Dave’s cube-mate was grabbed from his multiple week stint of fixing threading bugs into a meeting and shouted at for what seemed like forever. Dave could hear the muffled shouts. “Because your component isn’t finished, you are personally jeopardizing the future of the entire company!”After a particularly fruitless bug hunt, Dave had no idea what could be causing his race conditions, so he figured he’d ask Bob Eins. He described his problem. Herr Eins glanced at his code for a microsecond and said, “There is nothing wrong in the platform. You are just using it incorrectly.”“Is there any documentation on how to do this correctly?”“There is no need for documentation. Just read the source code,” Bob Eins replied. He waved a hand and wandered off to do more template metaprogramming.Dave went to Bob Zwei next. “You know,” he began, “back when I was working on Project Volcano…”Dave didn’t want to look at the library sources, for they used every possible C++ misfeature and were as impenetrable as Mirkwood. After battling the digital equivalents of spiders and elves in a dense thicket of intertwined templates, he finally found what he was looking for: a helper class for the signal system. It was unusual, in that it had a comment, possibly the only one in the entirety of the Bobs’ code. It looked like this:
Error'd: Adult Supervision Required
"I was found that my NAS was choking on small files," Lionel S. writes, "Now I know it was a marble all along."
CodeSOD: A Handle on Events
As developers, we try to write software that will be helpful to our users. Sometimes, we'll do key-by-key examination of what they're typing to do auto-complete. Sometimes, we'll look at a type-field entry to display the relevant subset of subordinate fields to be entered. Sometimes, we'll even try to coalesce error messages so that the user gets one message with a list of mistakes as opposed to one message per mistake.Of course, it helps if the logic to detect multiple errors and coalesce them into one is correct.Mike M. was supporting a system that had an event queue. In the case of this particular queue, the messages were all for the same condition. To be helpful, the cow-orker who wrote it decided to only display the pop-up for the first message in the queue and silently swallow the rest.For the longest time, the system generated a single message for the given condition and so only a single pop-up was ever displayed.Recently, something unrelated changed, and the system started generating a large number of identical events at once on the queue, which exposed a flaw in the coalescing logic; it took Mike four minutes of continuous clicking to get through the queue of event messages:
Editor's Soapbox: Processing a Rant
In addition to being your intrepid editor, I’m an independent consultant. People hire consultants because they want someone to “inform their process”. “How do we do Agile better? Do we do Scrum or Kanban? Can we do scrumfall instead?” “Should we do BDD, TDD, or ATDD? Or combine them? Are there any other acronyms we should be doing?”
CodeSOD: MacGyver's XMLHTTPRequest
In these days of browser standards, it’s easy to forget that once upon a time, simple tasks like an HTTP request from JavaScript were difficult or even impossible, and if you wanted it to work in every browser, you were going to have to write wrappers to try and create a consistent API.Zeke inherited an application back from those bad old days. It needs to poll a server, and based on the response, it performs an action, but it does this in an “inventive” way.First, they fashion a rudimentary enum:
Announcements: Release! at Ohio Linux Fest
To introduce myself, that’s me over in the right corner. Hi. You might remember that, a year or so back, this site got a face lift. We still love the way it looks, but, if we are being straight with you, the CSS and HTML are a damn mess. So, I’ll be re-building the site while maintaining the same look, and maybe writing an article here and there.Most of you are familiar with Release!, the card game, which Inedo came out with last summer. The support on Kickstarter was fantastic, especially from the Daily WTF community. I was the lead game designer on Release!, and I was also on the team for our more recent Kickstarter campaign, ABC++.This October, I am pleased to participate in an event in my town: Ohio Linux Fest in Columbus will feature Release! during its game nights, and give me the opportunity to speak about the overlap of game and software design.Catch my talk, Pinochle, Dungeons and Dragons, and Software Usability, as well as some Release! demos during Friday’s happy hour, and at the afterparty.The talk revolves around how board games utilize a very similar design infrastructure as software UIs to communicate with their users. It mostly discusses the lessons we can take from these cardboard interfaces and how to apply them to digital ones.God, that sounds nerdy as hell.Anyway, I will be sure to bring some TDWTF Mugs, and copies of Release! with me too. So, if you don’t have the game yet you might wind up scoring a free pack![Advertisement] BuildMaster is more than just an automation tool: it brings together the people, process, and practices that allow teams to deliver software rapidly, reliably, and responsibly. And it's incredibly easy to get started; download now and use the built-in tutorials and wizards to get your builds and/or deploys automated!
You're Not My MIME Type
Andrew performed corporate support for a giant multinational. One day, he was assigned what looked like a straightforward bug: a new Intranet webpage for one business unit was failing to accept CSV spreadsheets containing product information from another business unit.After obtaining the proper permissions, Andrew first attempted to duplicate the issue. He browsed to the Intranet upload page, then tried to upload the user’s example CSV files. Each attempt failed with the oh-so-helpful message “Invalid file type.”Well, they were perfectly valid CSV files. Andrew tracked down the developer support contact for the site—Brian—and forwarded him the ticket.Not an hour later, the ticket boomeranged right back to Andrew, with a note from Brian attached. The code that handles file uploads is a third-party library. You’ll have to contact them for help.Ugh. The very thought set Andrew’s teeth on edge. First, he decided to see if there was the slightest chance of resolving the error himself. He googled every search string combination he could think of for the library name, error, scenario—no dice. The company website offered no useful documentation, either. It had support forums, but they were ghost towns.Andrew’s dread amplified. Realistically, this wasn’t going to get fully resolved before the heat death of the universe. That whole time, Andrew was sure to have users breathing down his neck. His next effort was to get a workaround in place. After making several phone calls and painfully backtracking his way to the people in charge of the dual business unit venture (“Tiffany? Oh, she doesn’t even work here anymore. You want Rob!”), he arranged things so that his users could email their CSV files directly to one person in the other business unit.These herculean efforts garnered Andrew nothing but huffy scorn. “This is really inconvenient for us,” nagged the user who’d logged the ticket.“It’s the best we can do until we get this third-party code fixed,” Andrew replied, taking it in stride.Well, he’d done what he could. It was time to give third-party support a call. After navigating an extensive phone tree, he had a (presumed) live specimen on the other end to whom he could explain the issue.“So why’s this happening?” he asked.“That doesn’t sound familiar,” Carl, the rep on the other side, told him. “We’ll have to try to duplicate the issue on our end. Do you have some of these files?”“Yes, I can email them to you,” Andrew said.“Great! We’ll test that out and let you know what we find.”To his credit, Carl called back within a few days to notify Andrew that the behavior had been duplicated. However, he didn’t know what was going wrong either, and would have to escalate the ticket on his end.A few weeks later, Andrew received another call from Carl. “All right, this is admittedly a strange case. Let me explain. To determine a valid file type, our code checks and ensures that the MIME type of an uploaded file matches the known MIME types associated with the file extension. It does this by looking at the beginning of the file and following some rules of thumb.”“OK,” Andrew said, furiously scribbling all this down in a notebook for future reference.“It’s a safety feature,” Carl said. “Looking at your example files, they all begin with entries that start with C, then a space.”“Yeah,” Andrew confirmed. “Those are part numbers.”“Well, back in the days of punch cards, FORTRAN programs indicated comment lines by punching a ‘C’ character in the first column, usually followed by a space.”Andrew froze for a few seconds. “Wait—so your code sees our part numbers and concludes the file is a FORTRAN program?”“I’m afraid so,” Carl said. “It’s working as designed.”“Working as designed?! It’s not flipping working at all!” Andrew cried.“This is expected behavior given your input,” Carl said. “You can edit your CSV files to not start with C-space values, or modify your logic around our library so that—”“No, I can’t do either of those things!” Andrew cut him off. “The users aren’t gonna change their files, and I have no access to the code! Couldn’t you edit the library to not make that check, and just be happy with a .csv file extension?”“We’re not prepared to do that at this time, but we can file a feature request.” In other words, Sorry, buddy. Your company doesn’t spend enough money with our company.“Fine,” Andrew growled, then hung up the phone. He pulled up his original support ticket to add this information and escalate it back to Brian, wondering how many minutes it would take to get kicked back with another blasé retort. As always, thanks for reading! If you like my articles, you might just love my new sci-fi/fantasy adventure novel about a knight who travels the galaxy with a starship, going on quests and getting into mischief. It has no WTFs in it (intentionally anyway), but hopefully the sword-fighting and deadly court intrigue make up for that. Enjoy! -Ellis[Advertisement] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too!
Error'd: The Little Application That Couldn't
"I don't know what it was trying to do, but it just couldn't do it," Bert writes, "It also looks like it couldn't finish the error message."
CodeSOD: Sorting Cabinets
Sorting. It’s a well-studied class of problem, with a number of well-understood solutions. These days, pretty much any time you need to sort a collection, there’s a language-or-framework-provided function that handles it for you. Sure, a Better Idiot™ might try and implement their own sorting algorithm from scratch, but your Regular Idiot™ just has to call .sort- it’s Idiot Proof™, rightWell, David S. found a better idiot.
Registered Students
Tim C. took pride in his work. He debugged Clockaburra, a timetabling and management suite, used in Australian high schools. Oftentimes, it was a simple problem that could be reproduced after a quick phone call from a client- usually a vice principal or the secretary. It’s when a bug can’t be reproduced that things get tricky, but Tim had the solution for that as well.One day, he got a call shortly after lunch from a Mrs. Harriet, the vice principal of Charles Perkins High School. “All of our mathematics classes have disappeared from the schedule,” she said. “It just happened this morning.”“What was the last thing anyone did to the schedule before the error?”“Oh, I wouldn’t know,” Mrs. Harriet said. “There’s a few of us who use it. It could have been anything, really.”This was, of course, the worst-case scenario. Tim had to go with Plan B. “Okay, I’m going to need part of your registry tree.”Step-by-StepStandard procedure of quality assurance is to recreate the reported environment as closely as possible, then isolate all the variables which could cause the issue until you find the root cause. Due to Clockaburra’s architecture, the easiest way of recreating the user’s environment on his machine was to get the client to send him the registry tree for Clockaburra in a .res file.“Oh, I’m not sure I could do that,” she replied. “I wouldn’t know how.”“Oh, it’s easy,” Tim said. “I’ll walk you through it.” Although it nearly broke his stress ball, he managed to guide Mrs. Harriet through the process. Then he walked her through attaching the file to an email, which was a bit of a puzzle for her. The email arrived, titled, “VERY IMPORTANT FILE”, with a .res file attached. The file was a surprisingly large 5MB, but Tim assumed they must just have an unusual installation on their end. He updated his registry with that file and rebooted.Identity CrisisTim blinked. His screen displayed a login that read Charles Perkins High School. Above that was an image of Charles Perkins in his football kit. He tried his credentials and was met with an “Invalid Username” error.His phone rang. It was Mrs. Harriet, who was eager to get all of those mathematics classes back on the schedule.He laughed nervously. “It’s… uh… well underway,” he said. “I’ll get back to you with a full report once we have it fixed.”Things not well underway, it was his turn to call his tech support, Bennelong.“This is a first for me,” BEnnelong said, after taking one look at Tim’s new login screen. “What did you do last?”“I was updating my registry with one a client sent. She sent me the tree for Clockaburra which shouldn’t have-”Tim remembered that the .res file Mrs. Harriet had sent was a chunky 5MB. She had sent her entire computer’s registry, not just for Clockaburra. His computer was tricked into thinking it was hers.Academic DiscretionBennelong used System Restore to get Tim’s system back to just before the call with Mrs. Harriet. Tim isolated the Clockaburra registry tree in the file, and soon pinpointed the issue as some invalid settings. Mrs. Harriet- or someone else- had blindly mis-configured the application in the most creative way Tim had seen yet. He returned Mrs. Harriet’s phone call late that afternoon with instructions on how to fix the problem.“That took quite awhile,” she said. “Nothing serious, was it?”“It was more of a snafu on my end,” Tim admitted. “I actually had to call tech support to get me out of a jam. I’m very sorry for the delay.”“Well, I won’t tell if you won’t,” Mrs. Harriet said. “We all have our moments.”[Advertisement] Release!is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!
CodeSOD: The Coercive Types
Loosely typed languages may offer certain advantages in terms of ease of use and flexibility, but they bring another challenge: it’s difficult to know what it is you’re looking at. With no compiler type checking, it’s hard to compare two things, and that becomes extremely problematic when you’re working with languages like, say, JavaScript.Ruby, in its quest to “make programmers happy”, took a simplistic approach to the Truthy vs. Falsy problem. False is false. Nil is false. Everything else is True. Ruby is often used by web developers, who may be more comfortable in languages like JavaScript and PHP.That is presumably why Lisa found this debacle in her code base, placed there by a co-worker who preferred other web languages:
The Graduate
Management will frequently hire young developers just out of school because a) they're cheap, and b) a developer is a developer is a developer. Graduates, especially from advanced degree programs, always have more advanced training than those with lesser degrees, and should be able to bring advanced skills to the table on day-1. Sometimes management gets lucky, and with a bit of proper guidance and oversight, the newbie can create something reasonably functional, performant and maintainable. This is not one of those occasions.In the aftermath of that strategy when management realizes that perhaps something is amiss and the usual threats of get it done don't seem to work, management crowbars open the purse strings and highly paid consultants are often sought after to clean up the mess. Sometimes the consultant can fix the mess. Sometimes the power of management to $*#%& up a project far outstrips anyone's ability to fix it.Jenny was lured hired to make some minor modifications to speed up a system of the latter variety that was written by an unsupervised fresh-out. It was way over budget, behind schedule, full of bugs and not feature-complete. The customers were not happy campers, and were not bashful about expressing their outrage dismay at the cost and progress. Basically, just another day in the office for Jenny.The application itself was run-of-the-mill case management software, storing basic demographic information about clients, the people that referred them and the history of their cases. It's a SQL Server database with ASP.NET forms to interact with the data. It should have been pretty simple stuff. Except...The design documents were literally coffee-stained napkins and Jenny was forewarned not to discard them. There had never been a DBA on the project. Naturally, this led Jenny down the rabbit hole...One of the first things she encountered everywhere was that columns that stored Yes/No data were declared as VARCHAR(20), and stored the literal strings "Yes", "No" and a variety of things that conjured up nightmares of FILE_NOT_FOUND.The application also had a number of data fields where the user must select a value from a pre-determined list, and the list is stored in the database. That is, there is a list of Suburbs, a list of PostCodes, a list of Illness types, etc. Rather than have tables called Suburbs, PostCodes and Illnesses, the developer opted for one table for all of them (interestingly, the booleans were not stored here, and commanded their own dedicated table). The table is called RefData_5, and whenever you want the data for any list (e.g.: the list of suburbs) you have to select from that single reference table and filter to get the records where RefType is "Suburb"). To complicate things, the table contained constant string values, numeric postal codes and enumerated values. Thus, once you queried the data, you needed to explicitly convert it to the correct type before you could use it.Of course, prior versions of the table still existed: RefData_4, RefData_3, RefData2 and RefData_1. Unfortunately, they weren't just there as unreferenced remnants. Some of them were referenced here and there throughout the code base and stored procedures, which led to all sorts of instability as table definitions changed over time.Adding to the woes, the code was not stored in any source control system; Jenny was handed the good copy on a USB key.Just to make things interesting, once a constant had been identified as applying to a particular situation, the PK of that constant record was not stored in the foreign record. Instead, the constant literal and the single character key (e.g.: "12345" and "P"ostcode) were stored. Of course, you had to ensure that you never used the same key for two different data types in the REF_DATA_n table, or going the other way might become an interesting challenge.Perhaps most impressive, is that the graduate managed to write queries on this structure. They were hundreds of lines of T-SQL if-else's and ran, well, glacially, and mostly returned the correct data. Mostly. So now Jenny gets to explain to management why their system that was inexpensively developed by the graduate ran so slowly and inconsistently, could not simply be tweaked to make it faster, and that a full rewrite was in order; all to hear in return: you're a highly paid consultant and you can't fix it?! Why are we paying you?[Advertisement] BuildMaster is more than just an automation tool: it brings together the people, process, and practices that allow teams to deliver software rapidly, reliably, and responsibly. And it's incredibly easy to get started; download now and use the built-in tutorials and wizards to get your builds and/or deploys automated!
Error'd: Blah, blah, blah!
"Believe it or not, I've actually seen less helpful content on StackOverflow," Luc F. writes.
Power Trip
It was a hot, cloudless summer day outside the headquarters of SmallTown SoftCorp. That didn’t matter much to Neil though, as he basked in the frosty air conditioning of the company’s modest, self-owned building. During the building’sconstruction, Neil oversaw the installation of everything from the demarc to the HVAC system. This made him feel like he had a hand in the arctic clime of the office.Those nice cool thoughts were torched when the power in the whole office suddenly went out. A chorus of profanity could be heard as all of the developers who hadn’t saved their work in a while lost everything. People began to stumble out of the windowless meeting rooms that had become blackened employee traps. “What the hell is going on?!” Jack, SmallTown SoftCorp’s owner, bellowed from his dim office. Jack slowly felt his way to Neil’s desk. “Neil! You know how this building is wired better than anyone! Get the power back on NOW!” Jack commanded, sweat beginning to form on his brow without the air conditioner combating the heat.Neil had to bite back an “I told you so!” During the construction, Neil stressed the importance of a backup diesel generator, but Jack shot it down as an “unnecessary luxury”. Thankfully, he was allowed to purchase UPS’s to keep their mission-critical servers alive. Neil got out his cell and phoned the utility company. The automated voice was happy to tell him there were no outages in the area. He deduced the problem must be isolated to their building.Neil grabbed a flashlight and headed to the pitch-black bowels of the building. He flipped the main breaker on and everything in the office sprung back to life. “Easy enough,” he said to himself. But the real problem would be figuring out why this happened. He looked around, all the wiring seemed to be intact. There were no signs of a cooked mouse that bit down on the wrong cord. He decided to check with everyone around the office to see if they noticed anything strange.He got several stock “I was working hard and everything went black!” responses. Jack said he was on an important call with a customer, but a check of his internet logs would probably show he was wasting time on Twitter again. As Neil approached Mike, one of their framework developers, he got visibly flustered. “Hey Mike. Did you notice anything happening before the power went out?”“What? Me? No! Of course not! Why would a lowly programmer as myself know anything about a power outage?” Mike replied with a nervous chuckle. “It sure is cold in here though! My cubicle feels like an igloo.”Neil looked up and noticed Mike’s desk was directly under an air conditioning vent. “Ouch, looks like you got the cold spot! Try to think warm thoughts.”Neil went back to Jack’s office to report the bad news that he didn’t have a root cause for the outage. Jack used his electrical knowledge (or lack thereof) to determine the air conditioning must be sucking too much juice on a hot day. “Turn the AC down immediately, Neil! We can’t have this happen again.” Neil obliged by setting it a few degrees higher and went back to his normal business.Later that afternoon, Neil was working on documentation when the office again went black. “OH COME ON!” a frustrated programmer shouted from across the office. “NEIL! I SAID THIS CAN’T HAPPEN AGAIN!” Jack roared out like a lion in the darkness.“I’m on it, Jack!” Neil replied, frustrated. Luckily he still had the flashlight on his desk and the power was back on in a jiffy. He knew telling Jack he didn’t have an explanation wouldn’t fly this time, so he would not rest until he found the culprit. Of course, there was no obvious cause. Neil searched the building top to bottom, and couldn’t figure out the cause. He swore to figure it out the following day.The next day was the hottest of the day of the year, and Neil dreaded the load the HVAC system was putting on the electrical system- and sure enough, the power went out again. Jack shouted his anger, and Neil scurried off to the basement to fix the problem. With the lights on, as he came back up to the top of the stairs, Neil spotted Mike trying to sneak out the side door with a large object.“What you got there, Mike?” Neil asked with suspicion.“Oh, um, nothing,” Mike stammered, as he turned towards Neil with a large space heater in his hands. “It’s just that it gets so damn cold by my desk, I decided to bring this heater in and, it’s probably just a coincidence, but when I do this…” Mike bent down to plug the heater in a nearby outlet.“Mike, NO!!!” Neil couldn’t stop him fast enough as the heater fired up for a split second before the eerie quiet of a power outage returned. “You fool! You can go explain to Jack why the power keeps going out while I go back to the stupid basement.”[Advertisement] Scout is the best way to monitor your critical server infrastructure. With over 90 open source plugins, robust alerting, beautiful dashboards and a 5 minute install - Scout saves youvaluable engineering time. Try the server monitoring you'll 👍 today.Your first 30 days are free on us. Learn more at Scout.
CodeSOD: Taking Exception
Like many enterprise organizations, Martin’s workplace decided that they needed to build a collection of .NET assemblies which would be used in every application they built, and would provide important facilities like error handling.And of course, not only would every application need to use these libraries, every application needed to make use of every component in them, otherwise why have the libraries at all? This meant that every Exception thrown by the application needed to inherit from the BaseException class:
Sharked
Andrew M. worked at a small company in Kansas City called EtherTrode. With one facility and about 20 employees, they designed and built custom Ethernet hardware and drivers to fill niche roles where the common integrated chipsets weren’t good enough. Their hardware worked quite well, which attracted the attention of a multinational conglomerate called Initech. Initech puchased EtherTrode, rather than develop their own Ethernet devices.Like most others at EtherTrode, Andrew was a jack-of-all-trades. On any given day, he might be doing anything from customer support, to application development, to general office IT tasks, and even once a bit of soldering. It was the general office IT tasks that got Initech’s attention: he was selected to work with Initech on integrating their networks.The first phase went more-or-less smoothly. Initech shipped Andrew a pre-configured Cisco router, and instructions on how to connect it. After a weekend of integration, EtherTrode’s network now had a permanent VPN tunnel to Initech’s headquarters in Detroit.Phase One was boring. Yes, there were minor screwups and a few WTFs due to some miscommunication and unnecessary outsourcing, but that’s a variation on the same story that’s been told a million times before. Phase Two, however, was the Grand Slam over the foul line, lightning in the whiskey warehouse, the Cheese Shop without cheese, and a painful urination upon a subway’s third rail…… Active Directory Integration.Once the networks were connected, Initech wanted to terminate EtherTrode’s Active Directory domain and move all of their accounts and systems into Initech’s domain. Contractors working for Initech prepared a new domain server and shipped it to Andrew. He received the system, racked it the next weekend, and powered it on. Everything seemed to work, and local systems joined to Initech’s domain without issues. Come Monday morning, the office was ready to resume business.Things turned sour around lunchtime on Monday. All morning, employees had complained about poor network performance. Their emails failed to send, and new messages failed to arrive. Tiny Subversion check-ins would fail more often than not, and even internal web pages took minutes to load- if they loaded at all. Worse still, Initech’s security officers had installed a new electronic lock system on EtherTrode’s building, which was connected to the LAN. By lunchtime, the locks refused to unlock, and Andrew had to physically unplug the controller unit in the server room to disable the lock so employees could actually enter and exit.The core staff of EtherTrode had an impromptu meeting shortly after lunch to discuss the issues. Lyle, another engineer, arrived late. “But I know what the problem is,” he explained.“I noticed the lights on our core switch were blinking like a strobe light in a tornado, so I fired up Wireshark.” A few of the engineers nodded, and Andrew wondered why he hadn’t thought of that. EtherTrode made Ethernet equipment, and Wireshark was an invaluable tool for examining the behavior of their devices and networks. It was the best way to make sure their hardware complied with Ethernet and TCP/IP standards, and it was really good at not interfering with their network while doing its monitoring. “In short,” Lyle explained, “there’s a device at 192.168.16.245 that’s issuing tens of thousands of broadcasts per second. The switches are dropping frames, and the IP stack on everyone’s workstation is working overtime processing irrelevant packets.”“254, you say?” Andrew said. He frowned. “That’s the IP address of our new domain server…”“Can we shut it down?” asked Ryan, their boss. “Rollback to how our network was last week?”Andrew shook his head. “I’ve already joined everything to the new domain. If we shut down the controller, no one will be able to log in or access network resources… not that they can now.”Lyle spoke up again. “The traffic looks pretty fishy. I think the server’s got some sort of malware on it. Can we log in and see what it’s doing? Run an antivirus or kill the process?”Andrew shook his head again. “Initech has it locked down tight. I can do some basic domain admin tasks, but I can’t actually log into the server.”“Alright,” Ryan said, visibly irritated, “Lyle, give me your Wireshark capture. I’m going to go down to the coffee shop for their wi-fi, and I’m going to forward it to Initech and raise some hell.”In the meantime, Andrew and Lyle went back to the switch. Since the broadcast was on a single port, they blocked that port at the switch. The server kept shouting its head off, but now the switch dropped the packets. Doing anything that required talking to the domain server- like logging in- was painfully slow and failed half the time, but the rest of the network worked fine. That bought them some time while they waited for a better solution from Initech.The next day, Andrew came in, grabbed a mug of coffee, and picked up the top priority support ticket. This one was a customer support issue. They had uploaded their own Wireshark capture to an FTP server. Andrew downloaded it so that he could see why their EtherTrode equipment was misbehaving. When he went to open the capture, Wireshark refused to start- or more accurately, it was no longer installed on his system.“That’s strange,” Andrew thought to himself. Maybe a Windows Update messed up the registry settings, or something, so Andrew redownloaded Wireshark and ran the installer.Or tried to. The installer refused to run. “This publisher has been blocked by your administrator,” explained the error message. As if on cue, his email client dinged and he was a new memo from the Initech IT department:
CodeSOD: Filter Overflow
Onboarding was complete, and Denise finally had her PC. Time for her first assignment!"It's really pretty straightforward," her new boss had said, with a resigned look in his eye that betrayed it wasn't actually straightforward. "Your predecessor almost had this new CMS complete, we just need filtering on the frontend search."It wasn't glamorous, but it was probably a good way to get her feet wet in a new organization. The requirement was to fetch a list of image IDs that corresponded with a business ID so that users only saw the images for their group. Simple, straightforward, obvious. She had it done inside of a few days and sent to the users for UAT.And that's when the change requests started."Can you make it filter by state? Like, hidden images, public images, that sort of thing?" Sure, easy enough."What about filtering by upload date? Like if I gave you a date range?" Um, sure, but it'll add to the time...Even after the filter was in production, the list of requests kept rolling in, bypassing the helpdesk and going right to her email inbox. "We're getting a lot of spam images, can we filter so only verified users' uploads show up?"Denise's boss told her it'd be over faster if she just gave in and made the change. Management would ultimately decide to do it after wasting her time with meeting after meeting to discuss priority anyway."Can we put videos in the CMS?""Can we filter by tags?""I need to filter images that are actually images.""Can we sort on the tags?” How do you sort on tags? Denise wondered. Apparently, by their business IDs. Sure. Whatever."I'm still getting images that shouldn't be showing up. Can we filter for only images that show up?""There's too many images, can I limit it to ten per ID?"Finally, she ended up with this giant Ruby monstrosity:
Error'd: See Something? Say Something!
Patrick wrote, "I was at Penn Station in NYC, and, well, I just had to say something!"
The Depths of Insanity
George G. came to the Pierce & Pierce office in good spirits and with high hopes. After finally gathering the courage to run away from his previous job, which had involved maintaining a million-line, 15-year-old mess of a codebase, he'd spent the last month interviewing with nearly every tech company in his area. Here he'd found his Promised Land: a modern-looking, professional company with a suite of cutting-edge technologies and, most importantly, a new and interesting project to which George would be assigned.Or at least that was what Pierce & Pierce had promised at the interview."Well, you see, there's been a reorg." George had barely sat down at his desk for the first time when his manager brought him the news. "All new projects are on ice. We're gonna be putting you on our flagship product instead. Don't worry, we'll have something real cutting-edge for you soon!"Flagship product? That could only mean one thing: legacy code. Another aging codebase which, thanks to the company's "innovative performance-boosting management methods," clocked in at five million lines of uncommented, undocumented code. As much as George wanted to get up and leave at such news, he decided to bite the bullet and give Pierce & Pierce a chance ... for now.He received his first assignment almost immediately. The application failed to read a particular line from a config file, and the task was to investigate and fix the issue.Well, that should be simple, he thought. I just need to find the place where the config file gets opened, then there should be some loop that reads it and looks for that line. Easy-peasy.He submitted a one-hour time estimate, giving himself some leeway, then got down to hunting the bug.Unfortunately, things weren't so simple. What was supposed to be a quick, introductory trip through the codebase turned out to be a strenuous excavation through layer upon layer of abstract factory builders, inline lambdas spinning off separate threads, callbacks to callbacks, and other examples of architecture astronautics—all to simply read the configuration file.Four days later, George managed to find something resembling an error logger. He set a breakpoint and ran the application, hoping to work his way through the call stack to where the issue lay.Sure enough, the breakpoint was hit almost immediately. But even before George started reading the stack trace, he knew it wouldn’t be of much use. The list of classes looked something like this:
Bring Your Own Code: The End of the Lucky Deuce
What feels like forever ago, we introduced the Lucky Deuce casino contest. This is a series of challenges, brought to you by our pals over at Infragistics, where we call on you to help us build a “scoundrel’s casino”.Last week, we introduced our final challenge: take one of our casino games, add a betting system, and then build a strategy that lets you keep playing (by distributing the load across multiple accounts).Once again, we had a nice pile of great submissions, and there are two who are going to get to take home a nice TDWTF hoodie for their troubles. As always, check out the full projects on GitHub.For all of our winners (from this week or any previous)- or anyone who entered using Infragistics controls- expect an email in the next week or two to follow up about how best to get you prizes.WinnersFirst, let’s talk about Bruno’s solution. For bonus points, he decided that his system should be able to detect a user’s gender by their name:
'Tis the Season
Deep in the wooded vales of red state America, December is hallowed not just for hunting presents, but also hunting deer. Lo, the season opened on a Friday. Clayton’s consulting firm declared it Camo Day in celebration.Employees festooned themselves and their office in their brown-and-green finest. Some posted deer horns and small taxidermic animals in prominent locations. While this particular company stopped short of installing a shotgun in the kitchen, just in case a bear happened along, it was still the most redneck of wonderlands.Clayton could even swear he smelled hunting musk as he moved through the floor, trying to get back to his desk after an exhausting code review. And everywhere he looked, camouflage-print duct tape lingered like traces of scat: patching a hole in the carpet, propping up the back of a swivel chair, cradling a leaky ceiling tile …Both tape and musk led to his manager Buck’s office.“How you doin’, Clayton!” His voice boomed out from the office like a blunderbuss’ payload, halting Clayton in his tracks. “How’d that code review go?”Clayton peeked in to find Buck applying a piece of camo duct tape to a patch of ruined drywall behind his desk chair. He ignored the scene to reply, “Fine. John has some changes to make, but nothing major.”“Good, good.” Buck rubbed a fist over the newly applied tape. “Don’t mind me, I’m just taking the initiative to fix a few things around here.”Clayton debated whether to say anything. In the end, he couldn’t help himself. “Uh, all that stuff you’re fixing probably needs more than duct tape.”This prompted Buck’s ringing laugh. “If you can’t fix it with duct tape, you’re not using enough!” Finished with the wall, Buck turned, yanked his laptop out of its docking station, and began wrapping the camo-colored tape around it.Clayton really knew better, but again couldn’t help himself. “What are you doing?”“Decorating my laptop!” Buck replied.“But … you’re covering the vents,” Clayton managed around his shock. “It’s gonna overheat.”“It’s winter and it’s cold out! This thing’ll be fine.”“Win—you’re taking it outside?” Clayton faltered.“Out to my hunting blind! I’m cutting out early to get a jump on the season.” Buck reached into his pocket. Out came an obnoxiously sized lock-back knife that he used to slice a gap into the tape layer, allowing him to open up the laptop.“Why bother working remotely?” Clayton asked. “Just call it a week.”“The usual BS quarterly meeting is this afternoon—of course.” Buck rolled his eyes. “Gotta join the WebEx and at least pretend to pay attention.”The WebEx would handle both video and audio for the meeting. Clayton imagined the deer would take a dim view to budget projections, but Buck’s laptop did have a mute button.“Happy hunting, champ! I’ll have my cell phone in case you need anything.” Buck packed his laptop, then gathered his coat and a cooler that was almost certainly full of beer.“Uh, OK.”In the end, Clayton couldn’t complain about a manager-free afternoon. He returned to his desk, dug into his work, and all was well.A few hours later, his desk phone rang. Buck’s cell.Clayton internalized a curse and picked up the phone. “Hello?”There was nothing on the other end at first aside from scuffling, and a string of very not-internalized curses from Buck.“Boss?” Clayton prompted.“The damn thing’s a brick!” Buck cried.“What is?” Clayton asked.“It just shut down on me!”“Your laptop?”“And the damn meeting’s still on!” More scuffling noises from Buck’s end. “Hopefully everyone’s too busy snoozing to notice I fell off the WebEx. Hang on, I’ll be in the office soon!”Clayton didn’t bother stifling his groan, but managed to hang up before it escaped.Twenty minutes later, Buck stampeded into his cube, cooler and laptop in tow. He dropped the camouflaged computer onto Clayton’s desk, shaking out his hand. “Sumbitch shut down on me out of nowhere!”Clayton felt the waves of hot fury radiating off the laptop when he stuck his hand near it. “It overheated, like I said. You blocked the fans that keep air circulating through there,” he explained. “We gotta get this tape off.”“Nah! If it’s hot, we just gotta cool it down, right?” Buck opened up his cooler and pulled out a half-melted bag of ice. He then turned and dropped said bag directly onto the laptop.Clayton’s jaw fell. Should he bother to say anything? No, it never helped.“While it’s cooling off, I’ll need your computer to log back into the WebEx,” Buck said.Clayton suppressed his instinctive panic. “You have to leave it here. No ice or camo. I’m done for the day, and I’m not touching any more work until Monday! Deal?”“Deal.”With a collecting breath, Clayton logged out, then stood to gather his belongings. “There you go.”Buck clapped him on the shoulder. “Happy hunting, champ!”[Advertisement] Scout is the best way to monitor your critical server infrastructure. With over 90 open source plugins, robust alerting, beautiful dashboards and a 5 minute install - Scout saves youvaluable engineering time. Try the server monitoring you'll 👍 today.Your first 30 days are free on us. Learn more at Scout.
Classic WTF: The Non-Deleting Delete
It's a holiday in the US today, which means we're taking a 3-day weekend to dig back through the archives and find a classic WTF. One of my favorite features- one that we run far too rarely- are the true confessions. Sometimes, we are TRWTF, and let's applaud Matthew Schaad's story about his misuse of database triggers. - RemyIt started out as an average day for a developer like me. At 11:30AM, I was just getting into the office and fixing my second cup of coffee for the day. Being in the habit of coding till 3:00AM nightly, I was averaging about three to four cups a day. As I sat down at my desk to tackle one the several projects I had been assigned, I got a frantic call from the Director of IT, Jeremy.“Matt!” the telephone receiver shouted.“Yes?” I responded coolly, as I was used to hearing about fires that needed to be put out yesterday.“The reservation system is not allowing users to delete their reservations! Martin booked a conference room every Thursday for several years out, and now he can't delete it. Can you take a look at it?”“Sure, no problem,” I replied before hanging up the phone and going back to sipping my coffee.Jeremy was referring to our company reservation system. Similar to Outlook, we use it to manage shared resources, such as conference rooms, company cars and IT equipment. It isn't the most reliable system, and we constantly get complaints about it. Most of the time, though, the problems seem to arise between the chair and keyboard.So having gotten my marching orders, I opened up the database, wrote a quick DELETE statement, ran it, and saw that it deleted all the records for Martin’s recurring appointment:
Error'd: Crotia? Slovania? DO NOT USE!
"Canada? Yes! At least they got that one right!" Steve M. writes.
...454647484950515253