Feed the-daily-wtf The Daily WTF

Favorite IconThe Daily WTF

Link http://thedailywtf.com/
Feed http://syndication.thedailywtf.com/TheDailyWtf
Updated 2024-10-04 22:46
Best of…: Best of 2016: Overpowered
Merry Holidays, and as we coast into the new year, it's time for us to reflect on some of the best/worst moments of the past one. Today, we start things off with a BANG, and a reminder that electricity is a complicated beast. --RemyMike had a different perspective on wiring and cable management- because he worked at a factory which made wires and cables. It was the early–90s, and he was in charge of babysitting a couple of VAXes and their massive, 85lb hard drives. It was an easy job: the users knew the system and needed very little support, the VAXes were practically unstoppable, and the backup battery system could keep the entire thing running for over an hour.The computers supported HR and accounting, which meant as the year ticked towards its end, Mike had to prep the system for its heaviest period of use- the year end closing processes. Through the last weeks of December, his users would be rushing to get their reports done and filed so they could take off early and enjoy the holidays.Mike had been through this rodeo before, but Reginald, the plant manager, called him up to his office. There was going to be a wrench in the works this year. Mike sat down in Reginald’s cramped and stuffy office next to Barry, the chief electrician for the plant.“Our factory draws enough power from the main grid that the power company has a substation that’s essentially dedicated to us,” Reginald explained. “But they’ve got a problem with some transformers loaded with PCBs that they want to replace, so they need to shut down that substation for a week while they do the work.”The factory portion was easy to deal with- mid-December was a period when the assembly line was usually quiet anyway, so the company could just shift production to another facility that had some capacity. But there was no way their front-office could delay their year-end closing processes.“So, to keep the office running, we’ll be bringing in a generator truck,” Reginald said. “And that means we’re going to need to set up a cut-over from the main grid to the generator.”From the computer-room side, the process was easy, but that didn’t stop Mike from writing up a checklist, taping it to the wall beside his desk and sharing a copy with Barry. Before the generator truck arrived, he’d already tested the process several times, ensuring that he could go from mains power to battery and back to mains power without any problem.The generator truck arrived a week before the changeover. The electricians ignored it for a few days. Just as Mike was starting to get worried about deadlines, he looked out a window and saw a trio of electricians, lead by Barry, starting to connect cables to it. Later that day, when Mike left to go to lunch, he walked past the generator truck, and noticed something odd about the cables- they were clearly single phase power cables.Typical residential power systems are single-phase alternating current- one peak, one trough. This creates “dead” moments in the cycle, where no work is being done. That’s fine for residential use- but industrial systems need three-phase power- three offset AC cycles that, when added together, guarantee current is always flowing.“Hey,” Mike said to one of the electricians loitering near the truck, “you’re planning to run some three-phase cabling, right?”“Nope. The factory’s shut down- this thing is just gonna run lights and heating.”“And computers,” Mike said. “The hard drives need three-phase power.”“We’ll have to order some parts,” the electrician said.A few more days ticked by with no three-phase connections, and Mike checked in with the electricians again.“The parts are coming.”At this point, Reginald came down from his office to the computer room. “Mike, Barry’s telling me you’re being a disruption.”“What?”“Look, there’s a chain of command,” Reginald said. “And you can’t tell the electricians how to do their job.”“I’m no-”“From now on, if you have any concerns, bring them to me.”The day of the cut-over, the three-phase cabling finally arrived. Barry and his electricians quickly strung those cables from the generator. Mike wasn’t exactly watching them like a hawk, but he was worried- there was no way they could test the configuration while they were working so hastily. Unlike single-phase power, three-phase power could be out-of-sync, which would wreak havoc on the hard drives. He thought about bringing this up to the electricians, but recalled Reginald’s comments on the chain of command. He went to Reginald instead.“Mike,” Reginald said, shaking his head. “I know you computer guys think you know everything, but you’re not an electrician. This is a factory, Mike, and you’ve got to learn a little about what it’s like to work for a living.”Now, the electricians and Mike needed to coordinate their efforts, but Reginald strictly enforced the idea of the chain of command. One electrician would power on the generator and announce it, “Generator’s running.” Another electrician would relay this to Barry: “Generator’s running.” Barry would relay that to Reginald. “Generator’s on.” Reginald, finally, would tell Mike.
Error'd: What's my Age Again?
"For your information, Walmart, no, I'm not too old to buy this game, no matter how many years old you think I should be," wrote Ryan F.
'Twas the Night Before Go-Live
Once again, we're hitting the holiday season. I had fun doing The PM Who Stole Christmas last year, so I decided to try my hand at another holiday classic. Expect your regularly scheduled Error'd tomorrow, but next week, we'll be revisiting our classic and best articles of the year. Happy Holidays! -- Remy’Twas the night before go-live, and all throughout git,
CodeSOD: 1 Moment in Time
On occasion, we've all faced a situation where we need to check to see if some internal application process has succeeded, or gotten stuck. There are many ways to accomplish this; some better than others. In the old days, folks used loops to count CPU cycles. Of course, as CPUs got faster, this didn't scale all that well. Now you can use myriad combinations of event handlers, semaphores, thread safe flags and threads. Or you can just use the time tested method of hard coding a sleep.Of course, this requires that you have a decent idea of how long something will take to complete. It also assumes that you know something about the delays that can reasonably be expected in the execution environment.If it's on your hardware, that may be reasonable. When it's on the customer's hardware in their environment, your ability to accurately guess how long stuff will take decreases exponentially (think solid state disks vs. local physical disks vs. network storage vs. anything in the cloud).Jerry inherited some installer software written by a former cow-orking cowboy coder named Mike. This software would perform several installation/setup tasks. Each used the same mechanism to see whether or not it had completed.Specifically, It would spawn a thread that did a sleep for a hard-wired period, and then check to see if the step that was running had completed or not. If not, it reported an error.Except that it frequently (e.g.: most of the time) reported that the task had hung or failed, when it was simply still (legitimately) running. Mike had made several fixes to this end, but never solved the problem. This annoyed the operations team to no end. Jerry was tasked with figuring out why it would incorrectly flag failures so often.After some spelunking, Jerry had a headdesk moment when he found Mike's fixes in source control. See if you can spot the problem:
Announcements: Submit WTF Code Directly From Visual Studio
A little more than five years ago, we published a plug-in that allowed you to submit code directly from Visual Studio to The Daily WTF. However, in the years since, that style of extension was deprecated in Visual Studio, and the SubmitToWTF API was lost in the latest site redesign.The loss was felt by many users. Without the plug-in, submitting bad code requires first printing it out, putting it on a wooden table, taking a picture of it... then printing out the picture, scanning it, then uploading as a PDF to the Submit Your WTF form.With Christmas right around the corner, we thought it would be the perfect time to restore this much-needed plug-in. Thanks to Ben Lubar, the SubmitToWTF extension has been rewritten and is available directly from the Visual Studio Marketplace.
The Call of the 90s
The 90s were a weird decade, and not just because of a strange obsession with flannel. Computers were just becoming a mass-market phenomenon, and nobody really quite grasped what that was going to mean. When I entered college in the late 90s, the campus was still littered with dumb terminals wired up to the VAX. Just a few years before, they’d installed the latest thing in networking- 100Base-TX Ethernet- to all of the dorm rooms and most of the classrooms. They loved their brand new network, and didn’t want punk kids messing it up, so you couldn’t just connect your computer to the network (you probably didn’t have a network card anyway). Instead, they had an outside vendor set up an office in a storage room on campus. You had to lug your tower over there, they’d take your computer for a week or two, and then give it back to you with a new NIC, a bunch of crapware, and a note which said your computer was cleared to use the network. You could then take that note over to the IT offices, and they’d put in a work order to activate the network port in your dorm room, and give you an Ethernet cable. Oh, and this entire process cost $200.The 90s were a dark, dark time.Eventually, they wised up, kicked the outside vendor off campus, and CS majors like myself got to make a couple of bucks installing NICs into freshmen’s computers. I think many of us might have had that sort of experience. Sabrina did a similar turn in her teens, helping a small ISP get people connected via modem or ADSL, but encountered a few… special edge cases.One call was a pretty standard example: a family had just gotten a new modem, and wanted to connect their computer to the information superhighway… but couldn’t. Yes, they had a dialtone. Yes, the modem dialed. No, it couldn’t connect. Remote diagnostic options exhausted, Sabrina went on site. This small ISP primarily served a small city, but that city was surrounded by a large stretch of rural farmland that stretched into mountains. Before long, Sabrina found herself on gravel roads, driving past signs that warned, “No Trespassing” (and had been peppered with shotgun pellets to drive home the point). Eventually, she found the house- a quiet little place nestled well back into the woods. She greeted the family, waded through a handful of screaming kids, and went straight to the phone first. She picked up the handset.There were voices talking on the phone.“Do you have another handset?” Sabrina asked. “I’ll need everybody to hang up so I can debug things.”“What?” the mother said, “Oh, no. We’ve just got the one. But it is a party line.”“A what?” Sabrina asked.“A party line. We share a loop with the whole neighborhood.”Sabrina was a little flummoxed, since this hardly seemed like a neighborhood- their nearest neighbor was miles away- but as someone who grew up in the city, she’d never even heard of a “party-line”, as they were mostly extinct everywhere in the country. Instead of giving each subscriber their own phone line, sometime in the past century, the phone company had installed a loop of cable all around the region. Each handset was attached to the entire loop, which meant everyone in the service area shared a single phone line. There was no call privacy, and there was certainly no way to use a modem under those conditions. Sabrina explained the problem to the family.“Well, the phone company has been after us to get a single line, but it just seems so silly when what we have works just fine. But, I guess if we need it to use the Internet…”After leaving that strange intersection of the 19th and 20th centuries, Sabrina’s next call took her back into the city. There was a customer complaining that they’d just installed the software that came with their ADSL modem, but couldn’t connect to the Internet. This brought her into her town’s business district, where she found a the law offices of Duey, Cheatum & Howe. Mr. Duey brought her to his shiny new computer, a Pentium with a Yamaha CDR100- the $5,000 CD-R that Sabrina never thought she’d see in person.“Now,” he said, “let me show you what I did.” He put a CD into the regular optical drive. This CD was not one of the ISP’s discs, but instead, was a duplicated disk simply labeled with black marker as “Internet”. Once he brought up the installer, however, it was clear that it was their software. He went through the installer, completely ignoring Sabrina until he had finished demonstrating exactly what he had done to set up the Internet. Once the he failed to connect, he turned to her and said, “Well?”“Well… I’ll need to look at your modem.”“My what?”“Your modem? The thing you hooked up to the ADSL line?” Sabrina asked. “It’s a little box…”“I don’t have one of those. I just have the CD.”“Right…” Sabrina said. “But… you need one. A modem, I mean.”“What? That’s nonsense. My neighbors bought Internet from your company. I borrowed the disc, made a copy, and now I want Internet at my office. I copy all sorts of programs from my neighbor,” the lawyer explained. “I paid all that money for a CD burner, and I want to get my money’s worth out of it.”“You… you’re a lawyer,” Sabrina said, scandalized. “That’s illegal. And… you copied our software, installed it without a subscription, and then called us for technical support?”“Honey, I think I know just a little bit more about what’s illegal or not. And you know what is illegal, offering a service that doesn’t actually work! I want the Internet on this computer, and I want it now missy.”Sabrina confessed that she couldn’t get it to work, and left him with the number to the ISP’s sales department. She then beat a hasty retreat and went out on the next service call.[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: Recycled Code
Hannes has inherited a legacy project. Like most legacy projects, it has no real documentation, the code is a disorganized mess, and making any change runs a non-zero risk of completely knocking over the house of cards.What few comments the code has tells us things like this:
Error'd: Now Playing - Exception, The Movie
"While browsing the IMDB Android app, I finally found a hacking movie that gets the details right!" writes Jamie.
Pulling Teeth
"Jackie, Brian is leaving the company in two weeks," the boss revealed behind his closed office door. "You'll be taking over maintenance for CONLAB."Jackie's eyes went wide. Brian was a guru within their IT department; his departure would surely cause a stir. CONLAB was just one of his holdings, a real database-maintenance workhorse that several large internal business units relied upon."To get you familiar with it, I'm gonna have you take over some of Brian's open feature requests," the boss continued. "I'll email you the details.""Sure!" This was good. Jackie could learn the ins and outs of the code while Brian was still around."Great! Make sure to arrange some one-on-one time with Brian as soon as possible," the boss said.Jackie was optimistic about his increased responsibility at first. He already maintained a few smaller apps, and was sure he could make CONLAB "his" fairly quickly.Unfortunately, getting his feet wet was hard when the pool turned out to be a desert mirage. Brian's calendar in Outlook was unpopulated. His cube was always empty. He never answered emails, never signed into Lync, and let every phone call dump to voicemail. Wall-to-wall meetings? Flaking out? Either was possible."Don't worry," the boss told Jackie. "I'll tell Brian to give you some time on his schedule."Nothing came of this confident offer. As the days slipped by, Jackie had to get creative. He pounced on Brian in the one place everyone wound up at one time or another: the restroom.Jackie explained how he'd be taking over CONLAB once Brian was gone. "I wanna start working on feature requests right away, but I'll need access to the code first. Can you help me with that?" Granting the proper permissions would be a single mouse-click operation in their project management tool."Well, it's complicated," Brian said. "The project lives in two git repos: one with the supporting library, one with the app itself."Jackie frowned. "Really? Why?""It'll make sense when you see it," Brian promised. "Let me finish some refactoring first, then I'll grant you access."Three days passed with no further progress. Jackie managed to corner Brian in the bathroom and ask again."Give me two more days," Brian said.The extended deadline didn't help. Desperate, Jackie sought help from Alisa, the system administrator, and her incredible sudo-powers."Based on file names, I think this is the library he was talking about." Alisa pointed to her laptop screen. "But there are two git repos holding different versions of it.""Oh, geez." Jackie nursed his temple. "OK, let me try out the one that's been worked on more recently."Once Alisa granted the proper permissions, Jackie returned to his desk to examine the library. Its codebase lacked comments. It contained an if-statement body that failed to fit vertically on his 23" monitor. But worst of all, there were no test cases to be found."There are test cases for the application that also cover the library," Brian revealed in the bathroom some time later. But access to CONLAB's application code remained out of reach.Alisa and Jackie went through the entire list of projects in the project management system, opening any git repo whose name hinted at having something to do with CONLAB. In the process, they learned their boss kept sales figures and presentations in git, along with more personal items."Oh my God, is this a diary?" Alisa asked."Close it, close it! I don't wanna know," Jackie said, averting his gaze.Alisa grepped through the file system. Nothing looked remotely like code for CONLAB. She checked every file server that Brian may have had access to. She checked file servers that Brian shouldn't have had access to. She checked local production servers and even remotely based client production servers. No sign of CONLAB's code."Maybe he's bypassing company policy and using some other version control system," Alisa suggested.She searched for signs of Mercurial, Subversion, CVS, Bazaar, Fossil—all to no avail."Seriously, what the hell?" Alisa muttered.Jackie shook his head, sullen. "Right now, I have two theories. Brian's either storing the code directly on his dev machine, or, CONLAB isn't actually an application at all.""Not an application?" Alisa repeated."CONLAB has no UI. It just processes database entries. So it could just be a batch file running in the background all the time," Jackie explained, then straightened as a third possibility occurred to him. "Heck, that might even be giving Brian too much credit. Maybe he's been handling the database updates manually, every 12 hours, for years now."Alisa's eyes went wide before she sobered again. "Today's Brian's last day. What'll you do?"Jackie stood up and scouted past the cubicle walls. He saw the familiar flicker of bad flourescent bulbs, heard the laughter of coworkers talking about anything but work ... and spotted Brian heading toward the men's room for what might be the last time."I'm going in," Jackie replied.[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: Not Getting the Getters
The number of customers that might purchase your software has a detectable impact on how you develop that software. If you’re making a smartphone time-killing game, for example, there are potentially hundreds of millions of customers for that game. This drives software in two directions- you have your mounds of shovelware crap that just hope to make a few bucks fleecing suckers, and then you have the tight competition that optimizes the design of the software.Contrast that to “enterprise” software. If you’re making an ERP, how many potential customers do you have? Thousands? Tens of thousands? And each one of them is going to want something different from your product, so you’ll need to either pile on features or build an Internal Platform that lets them customize it. It doesn’t matter how much money is in this market, or even how many users there are going to be- it’s all about the number of customers that might pay for your product. This, I suspect, is a large part of why enterprise software is terrible, and I think it lays out a corrolary to Remy’s Law of Enterprise Software: the narrower the audience, the worse the software is going to be.Which brings us to the code sent in by Jason F. Jason recently finished a contract to “modernize a PHP web app for agricultural consultants.” About twenty or so developers have touched this application at one point or another, and Jason is simply the latest one through the revolving door. A niche market, a series of developers who have never talked to each other, and as the topper, it’s built in PHP.One of the preceeding developers left behind this unusual approach to object-oriented programming in PHP…
Easter Eggs
Ada worked in QA in the Netherlands, testing a desktop application for a German bank. The app was simple: a C/C++ app that scanned in paper forms, read them with OCR, and processed their contents. It was constructed, as was the fashion at the time, from a number of separate DLLs, each serving one and only one purpose. It was usually fairly boring work, but it was paying for her education, so it was worth putting up with.One day, however, it stopped being boring. The error message she was looking for was meant to say something along the lines of Name field is not filled out, indicating that—surprisingly enough—the name field was blank. Pretty routine test. The message that appeared, however, was ... different. It read, You stupid woman.Ada stared at the message for a moment, then looked around, trying to see if anyone was snickering. Was this a prank? Was someone mad at her? Did they deliver her a dud build just to insult her? Or had her computer been hacked? Was she seeing things? Going insane? What the heck was going on here?!"Nobody's going to believe this," she muttered to herself as she took a screenshot. Then she printed it and carried it to her coworker's cube. "Bernd, I know this is weird, but ..."No sooner had Bernd seen the screenshot than he pinched the bridge of his nose, looking tired. "Thanks. I'll take care of it.""You believe me?" she blurted before she'd even realized it."Yeah. I know exactly what happened here."Slowly, she managed to coax the story out of him. You see, in the Netherlands, you're forced to work your notice period, with no option to leave earlier; you're expected to be professional enough to keep doing your job the whole time. At this company, the notice period was two months ... and Edwin, one of their colleagues, hadn't been very pleased with the company when he'd resigned."I'm still trying to find all the blasted things," Bernd confessed to Ada."It can't be that hard," she protested. "We've been over this thing a dozen times in the last two months.""He only left last week," said Bernd. "And a lot of them are on random timers. They don't show up every time, only one in three, or after it's been open for ten minutes, or an hour, or a day."Ada whistled. "Are they all this bad?""This one's my favorite," he said, pulling a screenshot off his cube wall. It was a message box just like the one she'd found, only this one read Give me back my bike!—a reference to WWII, when Germany had impounded bicycles in Holland to pay for the war effort."If the bank had seen this ..." whispered Ada, horrified.Bernd nodded. "That one only showed up on Tuesdays."With Ada's help, Bernd managed to remove another dozen message boxes before they shipped live—and three more after, under the guise of security patches. Starting with the next hire, the company shortened their standard leave back to the typical one month, and started a new policy: developers who were leaving the company would be moved to the testing department for the duration of their notice period, just in case.[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: This is the Endian
Anyone who’s ever needed to write cross-platform code in C or C++ knows that TRWTF is endianness. Your options are either to use a lot of platform specific preprocessor macros, or to coerce all of your data into your own specific format, for portability.Adam H’s company took the latter approach, implementing a ByteWriter class. It was relatively easy to use, with code that looked something like this:
Error'd: Null and Vague
"UPS has sent my parcel to the corporeal equivalent of /dev/null," wrote Steve J.
CodeSOD: Un-Encoding
Felix caught a ticket about their OpenId authentication. For some mysterious reason, it had started failing around 30% of the time, specifically because the access token returned by the service was invalid.Felix had originally written the code, but there was one problem: he wasn’t the last one to touch it. Another development team needed their own versions of the code, organized a bit differently, for infrastructure reasons. Eventually, the whole thing was turned into a drop-in library component that was used by all applications which depended on OpenId. The failures started after they made their changes, so obviously their changes caused the failures.Since the errors were intermittent, their first guess was that the bug was something intermittent- perhaps an infrastructure problem, or a race condition between interacting services? They couldn’t reliably reproduce the error, so Felix spent a lot of time eliminating possibilities. Trawling through the code wasn’t very helpful. The other team had been operating under unrealistic deadlines and hacked together something that worked and wasn’t too worried about how or why it worked. The result included lots of un-patterns (like anti-patterns, but without having a pattern to them), inheritance trees that desperately needed pruning, and old-fashioned SQL injection vulnerabilities copy-pasted everywhere.Eventually, buried deep in a common service adapter base class, no where near the code that was supposed to be responsible for managing authentication, he found this code for fetching the OpenId token:
Frozen Out
Lex was an employee at GreyBox in the late 90s, a PC-repair shop inside of a large electronics chain. He had spent the entire morning handling phone calls from customer after customer. Each of the calls was supposed to go to his co-worker Gerald, but Gerald hadn’t been picking up his phone. Each caller complained that Gerald had taken in their computer for repairs and not actually done the repairs.“I brought my laptop in yesterday,” one caller, a wheezy old man, said, “and the young man behind the counter just took the laptop and said, ‘come back in an hour’. He went into the back room, and when I came back, he looked like he had been drinking. You know, red faced and sweaty. And the laptop smelled funny- like corn chips. And it wasn’t fixed!”Lex, along with their boss Kyle, had long suspected Gerald’s… habits were interfering with his work performance. To wit, every time he was alone in the back room, he came out red-faced and sweaty. The accounting computer, also in the back room, frequently got infected with malware, despite only officially being used for running Excel. Gerald always covered his tracks, clearing history after he went about his ‘business’, and liberally spraying Febreeze in the back room afterwards, but they knew what he was getting up to.Unfortunately, Gerald was the son of the owner. It would take something like the Pentagon Papers to get him fired.“I’ll see to your laptop personally,” Lex told the old man on the phone. “I’ll also give it a thorough cleaning for the trouble you’ve been through.”The StingIf Gerald couldn’t be fired, then he had to be convinced to quit. He approached Kyle with an idea.“So, Gerald basically comes to work to… play on the computers, right?,” Lex said. “Well, I could write an application in Visual Basic that could freeze and un-freeze a computer screen.” At some point, a copy of Visual Basic had ended up on one of their diagnostic machines, and Lex had spent some time learning to use it. “It can disable the mouse and keyboard input, take a screen shot, then place the image over the entire screen. The entire process is reversible, too.”Kyle nodded, liking the general idea. “How do you trigger it on his machine without him noticing?” Kyle asked.“You can use another machine running the same process. It sends out a CmdPacket with the computer ID of the machine we want to target, along with a flag to either freeze or unfreeze the computer. When I notice Gerald’s not doing his job, I’ll freeze his computer from my own. Oh, and we’ll hide the process from the Task Manager, so he won’t be able to kill it.”“I don’t think Gerald’s ashamed of what he’s doing,” Kyle replied. “You could freeze… that stuff on his monitor, but he’d just turn it off if somebody walked in.”“I’m not talking about catching him red-handed. We just freeze his screen when he’s not doing work, and then unfreeze it when he decides to be useful again.”Kyle shrugged. “Well, it’s worth a shot.”The Happy EndingIt was all Lex could do to hide his glee that week. Each day, when Gerald came in to work, he and Kyle would keep tabs on him. When Gerald blew off the cashier station for the back room, Lex would press a key combo and enter the computer ID Gerald was at. Gerald would moan and shout expletives, then mumble something about a “lunch break” before vanishing for an hour.Gerald never got interested in doing work. Instead, after about a month of this treatment, he just stopped coming in. The owner called Kyle, asking if there was a problem with “malware”.“Well,” Kyle replied, “Lex and I haven’t seen any problems, but maybe Gerald should come in and remove the malware. It is part of his job, after all.” Gerald’s dad never mentioned it again.The little VB application that Lex installed remained on the computers at GreyBox for years afterwards. While they never had to punish any future employees for viewing NSFW content on company time, it did make for a fun gag during an after-hours LAN-party. [Advertisement] Infrastructure as Code built from the start with first-class Windows functionality and an intuitive, visual user interface. Download Otter today!
Representative Line: Off in the Distance
Drew W got called in to track down a bug. Specifically, their application needed to take a customer’s location, and measure the distance to the nearest National Weather Service radar station. It knew the latitude and longitude of each, and needed to find the distance between those points, and it was wrong. It could be off by hundreds or even thousands of miles, especially in more remote locations.This was the code in question:
The Infrastructure
George had just escaped from his job, a WTF-laden hellhole where asking for a test database to reproduce an issue resulted in the boss spending hours and hours hand-typing and debugging a fresh SQL script based on an old half-remembered schema.Initech promised to be a fantastic improvement. “We do things right around here,” his new boss, Harvey, told him after hiring him. “We do clean coding. Our development systems and libraries are fabulous! And each of our programmers get a private office with its own window!” Yay, no more cubicle!George climbed over the required HR training videos, slideshows, and a Himalayan mountain’s worth of paperwork, then headed to his new desk where a budget small-form factor PC with a single 17“ LCD monitor waited for him. ”Yeah, that’s real fabulous," he thought to himself. But perhaps it was just a placeholder system, quickly dug up from elsewhere in the building, to get him started while they ordered a proper developer-grade PC.It booted up and George realized he didn’t know his account credentials, so he wandered on down to the IT office to get set up.The IT Office, from the outside, appeared to be a large corner office, but inside it was cold and dark and of uncertain size, with the windows covered by blackout curtains and hidden oscillating fans blasting a chilly breeze through the office. All the room’s light coming from a single small table lamp situated at the sole occupant’s desk. Piles of unsorted equipment and cabling were scattered across the floor, barely visible in the poor lighting, a veritable obstacle course for any visitors with poor eyesight or agility. In contrast to the rest of the room, the desk itself was absolutely spotless, neatly holding the lamp, a keyboard and mouse, and one nice 40" display–nothing else. Not even a telephone. An empty office chair sat in front.As he entered the blackness, George could hear a rapid-fire chorus of clicking sounds–the kind that usually meant your hard drive had kicked the bucket–clustered around one floor-based pile of machinery which was only visible due to the incessant flashing of LEDs it possessed–LEDs which blinked in perfect time to the various patterns of clicks emanating from the area.George coughed to make his presence known, and the IT guy appeared near the desk with such silence that George wondered if he had materialized like a ghost. Due to the placement of their sole source of light, George could not even make out his features.“Hi, I’m George,” he introduced himself, extending a hand the man did not accept. “I just started here and I need an account.”The IT worker grunted slightly. He proceeded straight to one formless pile of equipment and sat down cross-legged next to it, right on the floor, moving so silently that George almost wondered if he had only imagined it. He made some barely-discernible motions in the dark, and a moment later a previously-hidden LCD monitor flickered to life, bringing new light into the room which allowed George to perceive that the monitor was precariously situated upon a pile of about five budget PC towers from at least a decade ago, heaped up like a deranged game of Jenga, the entire fixture surrounded by dark, snakelike cables of various types whiched meandered to and fro throughout the room.The screen came to, and George watched in fascination as it presented a Windows Server 2000 login screen. He then realized in repugnance that this pile of equipment was the very same one radiating the sickly click of dying hard disks. Surely this was not the company’s domain controller!The IT guy entered his login information, and upon his hitting “Enter”, the violent ticking of hard disks became frantic. The screen froze for a long moment–at the time it seemed like minutes–before switching to the classic desktop environment of an operating system serving well beyond its prime. The shadowy IT guy fished a mouse from somewhere in the darkness, almost as if by magic, and balanced it upon his scrawney left knee so he could use it. He clicked on the “Start” button.Nothing visibly happened at first, but the frenzied jackhammer of “Clicks of Death” told George everything he needed to know about the company’s IT infrastructure. Many long moments later, the Start Menu itself appeared, slowly drawing line-by-line into the desktop space at a painfully-slow rate. It completed rendering and the brutal ticking sound diminished somewhat.The IT guy attempted to open up the user manager, but as he clicked on its entry, the screen abruptly flashed to the bluest shade of blue, overlaid by a page of cryptic white text. George’s jaw dropped in horror but the other man remained perfectly silent. He reached a hand into the darkness and expertly stabbed the server’s reset switch with such ease that George surmised this to be a common occurrence, common enough for him to have developed impeccable muscle memory for the task.The system reset, flashed through its power-on self test, presented a RAID option ROM full of warnings about disk failure (which the IT guy completely ignored), and sat at the Windows 2000 Server loading screen for an eternity as its hard disks struggled from within to escape by the combined force of a dozen demon-possessed jackhammers.“Um, maybe I’ll just come back later?” George offered.“NO!” The man nearly shouted his first utterance since George met him, his retort sudden and forceful enough for George to flinch.And so George waited quietly, half-frozen in place by fear, watching the ghostly form of the company’s IT guy as he struggled through two more Blue Screens of Death on the company’s primary server before successfully opening the user manager and creating a domain account for George. Then he flourished, somehow producing a completed sticky note as if from thin air, and presented it to George. “It is done. Now go.”George took the sticky note and left the IT office as quickly and quietly as he could, carefully stepping around nigh-invisible pyramids of computer equipment and treacherous bundles of cable, eager to put the experience behind him and never step foot into the IT office again.As he entered the light outside the office, he peeked at the note which was scrawled with his username and password. But as he returned to his own desk to try the new login credentials, he could not expunge from himself an intense sense of doom, a growing despair that he had left one hellhole and entered a new dimension of pain and WTF-ery… [Advertisement] Atalasoft’s imaging SDKs come with APIs & pre-built controls for web viewing, browser scanning, annotating, & OCR/barcode capture. Try it for 30 days with included support.
Error'd: Lenovo Uh-Oh (and more!)
"I get it that some apps need special permissions, but a GUID is the digital equivalent of 'just trust me - I know what I'm doing'," Kenneth M. writes."Sometimes, vendors paint their accessories with golden paint," writes Geoffk C., "On the other hand, if you're Lenovo, you might produce a mouse made of solid gold."
Just The Fax, Ma'am
Gus had been working at his new job for a month. Most of his tickets had been for front-end work, making it easier and more efficient to manage the various vendors that the company did business with. These were important flags like "company does not accept UPS deliveries" or "company does not accept paper POs". The flags had been previously set via an aging web-based UI that only worked in Internet Explorer 6, but now they were migrating one at a time into the shiny new HTML5 app. It was tiring work, but rewarding.Unfortunately, as is so often the case, Gus quickly became pigeonholed as "the flag guy". Whenever it came time in the project to add new flags, there was no question who'd get the ticket. Gus could think of nothing he looked forward to less than touching the Oracle-based backend to the product, but unfortunately, it was his burden to bear.Adding flags to the database involved going through a special Database Committee. This was separate from the usual change request process. The committee was formed from all 6 of the company's database experts, and they personally reviewed every change. Worse, they were stodgy as all get-out. Any small error would get the change thrown out and the requestor berated for "wasting my time", along with a good helping of grumbling about "kids these days" and "narcissistic millennials" to boot.Gus submitted his change request asking for a new field 2 weeks ahead of when it was slated to go live, just in case. Submissions were due by Monday and were discussed on Thursday, with the results posted first thing Friday morning on the bulletin board outside the breakroom. Gus filled in every field carefully, checking the whole thing twice—all but the title, which he'd written as "New Database Feild". On Tuesday, he realized his typo. He quietly edited the form, saved it, then crossed his fingers.Friday rolled around and his change wasn't on the list, neither accepted nor rejected. Chewing his lip, Gus pulled up the change system and skimmed for his change.It was marked auto-rejected."What did you do?" demanded Chuck, the senior developer who'd been mentoring him."I don't know!" Gus replied. "Do you think it was the typo? But I fixed it on Tuesday!"Chuck slapped his forehead with his palm. "You changed the form? Don't ever change the form after it's submitted! That's grounds for automatic rejection!""It's okay," Gus said weakly. "We still have another week."Chuck just looked at him, shaking his head as he walked away.Gus spent the rest of the day focusing on the tedious form. There were dozens of fields, each with vague instructions, many demanding long explanations. Gus wouldn't be at the meeting to explain his change; he had to convince the committee it was necessary through the form alone. Worse, when he submitted it, it routed through an approval process that required him to chase down no less than 6 individuals to fill out their parts of the form."Yes, it's the same one as last week. Just put the same thing you did then. No, sorry, I don't know why it was rejected," he lied. "Can you just sign?"Monday came and went without another auto-rejection. Gus checked compulsively every day at lunchtime, waiting for the other shoe to drop, but his request made it to Thursday without incident. Finally, Friday came, and he made the trek to the breakroom to check the list.His change had been rejected.He didn't know why. He didn't care why. The application needed to be up and running for the first of the month—the following Tuesday. There was no time to try again. Gus walked over to Chuck's cube, his mind whirling. "What do you know about data hiding?"Chuck's face fell. He rubbed his face with one hand. "Dammit, this is why I try to pull front-end tickets.""You gotta help me, dude. I'm dying here!""Okay, okay, let me think. I've heard about some guys slipping an extra so-called check-digit into integer fields. You have to mask it out before the code gets to it, but ..."Gus grimaced. "I'd never get all the spots, I barely know the app.""You're sure you can't push back on the deadline?""Yeah. Can't we find a field that's unused or something?" Gus begged.An hour and dozens of SELECT statements later, they did just that. The Fax field wasn't populated in the old system; not a single vendor had a fax number worth recording. The new system hadn't bothered porting it over at all. Gus and Chuck hooked the flag up to the existing field. No muss, no fuss, and no database review.[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: Trimming the Fat
There are certain developers who don’t understand types. Frustrated, they fall back on the one data-type they understand- strings. Dates are hard, so put them in strings. Numbers aren’t hard, but they often exist in text boxes, so make them strings. Booleans? Well, we’ve come this far- strings it is.Tyisha has the displeasure of working with one such developer, but with a twist- they didn’t really understand strings, either. Tyisha only supplied a small example:
Awful On Purpose
Studying his new work contract, Stewart felt like he'd found a golden ticket. After 2 long and tedious years in the local university's IT department, he was happy for any opportunity to escape that hellhole. TLA Technologies looked like the Garden of Eden by comparison. Instead of being the only person responsible for anything vaguely computer-related—from putting up websites to plugging in power strips—he'd now be working with a "dynamic team of programmers" in a "rapidly growing company tapping into the web development market". Instead of dealing with tools and languages forgotten by history itself, he'd be using "modern, cutting-edge solutions" under "agile and customer-oriented methodologies". And instead of reporting to a pointy-haired supervisor who couldn't tell a computer from a toaster, he'd be working directly under Dave.Dave was a large part of why Stewart decided to take the job. Like most small company owners, Dave had taken it upon himself to personally interview the new hire—but unlike many of them, he had enough technical skills to make the interview feel less like a trivia game show and more like a friendly talk between fellow programmers. When Stewart's answers had strayed off the beaten path, Dave had been eager to discuss the solutions instead of just dismissing them, and when Stewart had started asking about the inner workings of the company, it'd been difficult for him to stump Dave with even the most precise questions. He seemed to know what his company was doing and what the coders need to deal with. What more was there to ask for from a boss?Stewart quickly scribbled his signature on the contract and handed it back to Dave."Welcome aboard!" Dave stood and extended his hand to Stewart. "You'll start next Monday.""Thanks for the opportunity," Stewart replied.Dave smiled. "Hopefully you'll prove yourself out on the battlefield. If you pull that off, maybe you'll stick around for a while!"In hindsight, the statement should've tripped an alarm in Stewart's mind, but being overjoyed with the prospect of a real job, he dismissed it as yet another cheerful promise. He left firmly convinced that all that glittered in TLA Technologies was gold.While Dave hadn't exactly lied, there were a few things he'd neglected to bring up during the interview. For example, when talking about "cutting-edge solutions", he hadn't mentioned TLA Technologies was using all of them. No two applications used the same tech stack. Each used whatever was popular at the time, with languages and databases from completely different ecosystems blended together until they worked. Luckily, Stewart got off easy with an only somewhat bizarre combination of a Node.js service running against a SQL Server database.The reason lay in what Dave had meant by a "dynamic team of programmers". Out of almost 20 developers, only 2 or 3 had any seniority. The rest were interns and juniors who came and went before anyone even learned their names. There was hardly a week that wasn't marked by desks being emptied, only to be filled by new hires within days. Everyone brought their own favorite technology to the potluck—sometimes introducing it through legitimate channels, sometimes sneaking it into parts of the application that'd be deemed untouchable once the original developer left.There was exactly one person in the company with enough authority to rein the developers in. Unfortunately, Dave spent most of his hours at water cooler discussions, exchanging the latest IT gossip and encouraging the devs to explore new tools. Occasionally, he retired to his office to explain to one of the people he'd just been chatting up that they were "no longer a good fit for the company".Stewart restrained himself from asking questions for quite a while, until one day he saw an empty desk a little too close to his own."Hi, boss," he said, entering Dave's office. "Do you know where Rob is?""Who's Rob?" Dave asked in a dry, uncaring voice, barely looking up from his monitor."Um ... Rob the front-end developer? He was supposed to finish a feature by today, and—""Oh, that Rob. We had to let him go. He wasn't pulling his weight on the new project.""What do you mean? He's only been on that project for 2 weeks!" Stewart fought the urge to start shouting. "We'd just started introducing him to the codebase. Surely you don't expect—""Look, Stewart." Dave interrupted him again. "When we bring a new developer into a project, even an intern like Rob, the customer expects our performance to grow. They want results, and it's our job to deliver them. Unfortunately, with Rob, the entire team slowed down as soon as he started working. I'm sure you understand why it had to be done."Stewart understood perfectly. With a polite nod, he scooted back to his desk, thinking about an escape plan.The days kept passing, and Stewart was still gathering the courage to hand in his notice. In the meantime, he struggled to figure out the twisted logic of the service he was working with; one of the previous developers apparently figured that Unix timestamps made great database primary keys. This worked well in development and crashed hard in production. To "patch" it, at every insert, the application would sneak a blank record in between other requests to lock the row for itself. Once it reserved the row, it would then update it column by column—and with some tables having up to 40 columns, that meant 40 UPDATE queries per record.It was a bizarre, Goldbergian design. Stewart decided to ask Dave to allow him to refactor it into something sane."Yeah, that is terrible," Dave agreed. "Why wouldn't they just use an identity field?""Exactly!" Stewart felt like he and Dave were finally on the same page. "It shouldn't take too long to fix, and it would certainly be much better for performance and development.""But the current code works, doesn't it?""Um ... for now it does, yes. But it's already a performance killer, and once more people start using the service, it's going to be much worse.""They aren't using it now," Dave said. "And the client hasn't complained. As a developer, I understand where you're coming from—but as a company owner, I can't agree to spending time on something that delivers no value."Stewart's eyes widened in shock. It was a catastrophe waiting to happen. At the current rate, the performance would get unbearable in a matter of months. And Dave was just dismissing it like it was nothing? What had happened to the "customer-oriented" company?"Besides, this is an opportunity to cash in on our support contract," Dave answered, as if reading Stewart's mind. "That's how it works in this business. If it ain't broke, don't fix it—unless the customer's paying.""I see," Stewart muttered. As he left Dave's office, he decided to take the advice to heart. Not only was he not going to fix the application, but more importantly, he also wasn't going to spend any more time trying to fix TLA Technologies. He walked towards his desk, unlocked one of the drawers, and pulled out a piece of paper that'd been waiting there for far too long. [Advertisement] Scale your release pipelines, creating secure, reliable, reusable deployments with one click. Download and learn more today!
CodeSOD: Indentured
Speaking with developers, I’m always surprised to find a surprising percentage are surprised and baffled by the “Fluent API”. This object-oriented convention is based on the Builder Pattern, and involves call chaining to construct a configured object. So, for example, if you needed to configure a SystemHandler object to have a series of LinkHandler objects, you might have something like this:
Classic WTF: Illicit Process Improvement
In celebration of Black Friday, also known as "Retail Hellscape", let's look at a retail-oriented classic WTF, which originally ran way back in 2007. We'll resume our regularly scheduled WTFs next week.--RemyChristian R. was in trouble. Despite his experience across hardware and software, desktops and server clusters, thumb drives and SANs, he hadn't found any freelance work in weeks. It was clear that he'd have to figure something out to pay the bills.In August, Christian applied at Drab's PCs, a large retail chain focused on computer hardware and software. He'd shopped there for years and had an impressive level of knowledge about their products, so he accepted a position in Technical Sales.After a few months of working at Drab's PCs, Christian grew tired of one of his tasks — manually keying in orders from the online store. The online store worked by emailing orders to individual branches across the country, which were then printed, given to the branch manager, and then distributed to employees. The employees would then key in each order, line by line, item by item.Entering orders was more time consuming than it had to be. Since each system had a barcode scanner, it didn't make sense to totally retype UPC codes and serial numbers. Having worked with PHP's image manipulation functions, Christian decided to take on a hobby project — a quicker interface to enter online orders.He bought himself a barcode scanner and got to work. After a few evenings of coding, he had a working prototype. It would take in an order email, convert UPCs, serial numbers, quantities, and prices to barcodes. The barcodes were aligned on the page such that the barcode scanner could simply be dragged from the top of the page to the bottom, generating a complete, accurate order.For a few weeks, Christian would use his application rather than typing orders in manually. Even after verifying that the order was complete and correct, he would still finish well before his coworkers. Gradually, word spread about his application, so he shared it with a few friends at his store.His circle of users were happy, but when word of Christian's application bubbled up to management, Christian was called into his boss's office. "Let's have a competition," his boss, Warren, began. "I'll have Bill enter an order against your program," he said. "He's the fastest at this, and I want to be sure that we're doing this the most efficient way we can."Christian and Bill started, and before Bill had fully keyed in the first item, Christian had processed an entire order. Happy with the results, Warren thanked Christian for his work and told him he'd talk to the branch manager about it.A few days later, Christian's branch manager, Larry, called him into his office. "I saw the order entry program you made," he began. "You're lucky I haven't fired you.""I... I'm sorry?" Christian was dumbstruck. "Did it mess up an order or something?""No. I just don't appreciate your interfering with the deployment of the new system." The "new system" had been coming soon since the day Christian was hired. Christian had never intended to interfere with plans made by corporate, he just wanted to make his life a little easier. He tried to defend himself, but Larry was unconvinced. His application had put him at odds with corporate.A year passed, the following winter came, and Christian was due for a performance review. After his boss, Warren, and the branch manager, Larry, had finished Christian's performance review sheet, he was called into Larry's office to review. Christian took a deep breath before walking in.Before Christian could even sit down, his review began. "You're not smiling enough," Larry began."You have the best feedback out of all of our staff, though." Warren was happy. "Customers love yo-""But they think you're cold and unfriendly. Why don't you smile more?" Larry interrupted."Really, though, your technical knowledge is great," Warren said. "And I've had more customers thank me for your hel-""I see here that you were almost ten minutes late on June 8th. You missed a team-building exercise!" Larry scowled and leaned forward. "Why don't you tell me about that day.""Well, there was a car accident which caused a delay," Christian began, "and I don't really have a good direct route in anyway. Still, I was still at my desk, ready to serve customers when the doors opened, so I don't think it was that big a deal...""Yes, yes. Well, let's cut to the chase. We've decided you can keep your job," said Larry with an insulting smile. "Sound good?"Christian was speechless. He looked to Warren for help, but Warren was timidly staring at the ground. He stumbled while mentioning a few improvements he'd made to the store, some thankful customers he'd served, but those comments were barely acknowledged."I'm not being considered for a raise then?" Christian finally asked."No, but you can keep your job," Larry reiterated."Will I be eligible for a raise next year?""No.""The year after that?""Y... maybe.""So, to get this straight, I have to work three years on my best behavior, be essentially the most incredible employee the store has ever had, and then, maybe I'll get a raise?""Well, if you put it like that...""Understood." Christian sighed and went back out to his desk. Two months later, he found a new position and has been there for several years now. He found out that corners were being cut across the board not only because the store didn't have a great year, but a new, expensive corporate office had been built that year.And that new system is still coming soon, but it's seriously right around the corner. [Advertisement] Application Release Automation – build complex release pipelines all managed from one central dashboard, accessibility for the whole team. Download and learn more today!
CodeSOD: Classic WTF: Injection Proof'd
It's Thanksgiving, in the US. Be thankful you're not supporting this block of code. --Remy
Error'd: Actually, My Father was a Folding Chair
Unpythonic
CodeSOD: The Rule of Ten
Florian’s office has a “rule of ten”. Well, they don’t, but one of Florian’s co-workers seems to think so. This co-worker has lots of thoughts. For example, they wrote this block, which is supposed to replace certain characters with some other characters.
Error'd: Does Anyone Here Speak CSS?
"If you ask me, it's not just English speakers that GSMArena is in need of," wrote Aankhen.
The 10x Developer
“You’re going to learn quite a bit from Burt,” Burt said. “He’s one of the best.”Davide blinked. He wondered if his new boss spoke about himself in the third person as a matter of course. Cautiously, he said, “Well… I hope so?”“Burt’s been with us since the beginning,” Burt continued. “Nobody but nobody knows our systems and our environment better than he does. He’s one of those… whatchacallits…” Burt glanced around his desk, and found what he was looking for- a glossy trade-mag with a cover story about the most productive developers. “A Ten-X developer. We’re really lucky to have him, and you’re really lucky to work with him.”Burt was not speaking in the third person. Burt, the CTO of the company, was a huge fan of Burt, the lead developer at the company. When Davide was hired on, CTO-Burt spent a lot of time praising the genius of Dev-Burt. Once David started working, he didn’t see CTO-Burt very much, but Dev-Burt also was eager to talk about what a genius he was.“Not just anybody can manage a system with 100KLOC, mostly by themselves,” Dev-Burt said. “But stick with me, and maybe you’ll learn.”Dev-Burt’s genius was questionable. Five minutes skimming the code-base made it clear that Dev-Burt had the coding conventions of a drunken lemur. The only thing that made the code even slightly readable was that most of it was in Python, and thus had to be indented logically. That was the only logical thing about it. Some variables were named in camelCase, others in snake_case. Half of them were just alwayslowercase. Function names were generally more consistent, only because there were fewer of them: Dev-Burt was the kind of developer that just loved to write 5,000 line functions. There were plenty of global variables, plenty of spaghettified code, and plenty “god” objects that mashed together thirty unrelated behaviors into one mess that behaved differently depending on which specific flags you set.Dev-Burt was too busy being a 10x developer to give Davide any guidance about what he was supposed to do. The only coding conventions appeared to be “Dev-Burt does whatever Dev-Burt wants.” From time to time, Davide would pick up tickets as they came through, tracking down and patching bugs, but mostly he tried to find opportunities to refactor the code and add some unit tests.This radical behavior lead to a tense meeting with the Burts.“Burt tells me you’re causing problems,” CTO-Burt said.“He’s making a mess out of my code,” Dev-Burt complained. “He’s making it more complicated!”“I was just refactoring it so-”“There he goes,” Dev-Burt said, throwing a hand in the air, “using his made up buzzwords. Look, we’ve got product to ship, and your refractioning isn’t getting us anywhere. I wouldn’t mind so much, but it’s eating into my own time, and making it harder for me to get work done!”“That’s bad,” CTO-Burt chimed in. “Because Burt’s a Ten-X developer. His time’s ten more times as valuable as yours.”At least, after the meeting, Davide had clear rules to follow: Dev-Burt does whatever he wants, Davide does whatever Dev-Burt tells him to, and Davide was not to touch any code unless it was to deal with a ticket assigned to him by CTO-Burt.This gave Davide a lot of downtime, during which he could watch the codebase grow. It was true, Dev-Burt was a 10x developer, in the sense that he could write ten times as much code as necessary and he’d often write the same code ten times, in different places in the application.One day, while wondering if this made Dev-Burt the first 100x developer, Davide received a new ticket. One of the automated jobs had failed, dumping a stack trace to the log, and it kept failing every hour. It didn’t seem to be having any other effects, but CTO-Burt wanted it fixed.Davide assumed there was an un-handled error, and dug through the stack trace to find the offending code. He was half right. Once he cut away the bulk of the logic, the basic structure of the method was this:
CodeSOD: Coldly Fused
In 1989, a pair of physicists claimed to have achieved the fusion of hydrogen at room temperatures. This came as quite a shock to other physicists, since fusion was only known to happen inside of stars. Within a few months, their claims were roundly rejected. Cold fusion became synonymous with junk science.Fast forward to 1995. when a small company wanted to make its own set of generous claims about its web application framework. Allaire, Inc (eventually bought out by Macromedia, which itself was eaten by Adobe), claimed that its Cold Fusion could solve all your web development problems. All of your web development challenges could be solved through the judicious application of CFML.Fast forward to today, where I’m surprised to learn that ColdFusion is still in active development. Brian recently had the pleasure of attempting to install it. First, he was annoyed at just the install size- 1.2GB for a web runtime and its assorted libraries. Then… the install failed. Brian poked around in the installer and found the following shell script:
The Logic Barrier
Brad was brought in as a new hire to work on improvements for a big-name ERP system. His supposed role would be that of the "input guy" for a new I/O module where engineers would enter some numbers, they would be crunched, and it would output a wireframe design of what they needed to build. While he got started, the development manager Cindy assured him they'd have an "output guy" soon enough.A month passed while Brad was making good progress. One Monday, Cindy walked up to his desk with a tall, dark-haired gentleman in tow. "Brad, this is Dmitry, your 'output guy'.""Hello Bard. I am Dmitry. Please to see you," he introduced himself with a firm handshake and large grin.After Dmitry got settled in, Cindy came back to Brad and told him in a hushed tone, "He just got here from Russia. He might be a little hard to understand, but boy can he code! You might need to give him a little guidance since your part of the application comes first, but I'm sure it will work out great!"So began several arduous weeks of Brad working on his input interface about 15 minutes a day, while assisting Dmitry the rest of the time. They got far enough to prepare an end-to-end demo for Cindy. When she arrived, Brad put in the specifications for some plumbing parts he found online. They were passed to Dmitry's code and out came what looked like a reject from Rorschach's inkblot test."Oh no!" Dmitry cried. "I think I forget to check in part of code. Need a little more time," he requested with a grin and a nod."Brad!" Cindy shouted, crossing her arms. "You obviously aren't getting through to Dmitry. Before the next end-to-end test, I want you to test your own components first, then cross-test each other's. I expect better results next time!"Brad ran through his own code exhaustively while Dmitry supposedly did the same. "Dmitry, I'm ready to exchange code when you are. Everything seems ok on my end.""Oh yes! My code is good, yes. Add a few more DLL, more logging. Great now," Dmitry assured him.Brad attempted to test Dmitry's code but couldn't even get it to run. He found several initial run blocks, proving Dmitry never even once ran his code because surely he would have noticed the myriad uninitialized collections and NullReferenceExceptions.Brad explained the situation and offered assistance but Dmitry assured him "No, no. You sit, I code and fix it up." An hour passed before Brad got an email from Dmitry with a .zip attachment that said "Deploy new DLL. Code working." Brad did just that only to find the code NOT working.With day turning to night on the Thursday before their Friday demo, Brad decided it would be more efficient to dig in and fix Dmitry's code himself. "Dmitry, just head home. I have some troubleshooting to do on my code," he lied. "I'll get it fixed up before the demo.""Maybe you need the coding practice!" Dmitry grinned while putting on his jacket. "Goodest luck, tomorrow bring great success."Brad committed the changes to Dmitry's code around midnight in what amounted to a complete re-write. Weary, he went home relieved that Cindy would be off his back for a while after the demo. That would give him time to figure out what to do about Dmitry.The following afternoon, the demo to Cindy went off without a hitch now that it had been purged of most of Dmitry's code. Cindy was pleased with the results, "great job gentlemen! How about we go out to the pub to celebrate! I'm buying the first round."Brad would have preferred to go home to collapse, but he couldn't pass up a free drink. The three of them engaged in awkward small talk over a round of beers. Dmitry offered to buy the next round when he switched to vodka. Cindy left after Round 2, leaving Brad and Dmitry who both seemed to have an unquenchable thirst.Brad was growing to like Dmitry when he ordered yet another round, putting them on the verge of not being able to stand. Dmitry leaned over to him, bleary eyed and said, "let me tell you a little secret." In perfectly clear English but still with a heavy Russian accent, he shared, "I apologize. I do the broken English thing so people don't expect a lot out of me. It's really the whole logic part of the job that I struggle with. I have a hard time understanding computers. Sorry you had to spend so much time fixing my code."The stunning revelation caused Brad to temporarily snap out of his stupor. When Dmitry went to the bathroom, he pulled out his phone to text Cindy, "We need to talk about Dmitry on Monday. Don't call me tomorrow, the phone ringing will hurt my head." [Advertisement] Incrementally adopt DevOps best practices with BuildMaster, ProGet and Otter, creating a robust, secure, scalable, and reliable DevOps toolchain.
CodeSOD: Just In Case
Brandon’s company had a lot of work to do, and not enough staff to do it, so they hired on some freelancers. They were careful about it, and felt like they’d hired some good people. One developer, in particular, was the kind of developer who not only understands the low-level Windows API, but actually knows how to use some of the undocumented corners of it to get things done.Most of the module was pretty good, but when Brandon double checked on the method for escaping disallowed characters from a URL, he found some problems.The function went character by character through the string, which was bad enough, but when it wanted to know if a certain character needed to be escaped or not, it called this function:
Error'd: Let's Eat
"Apparently, only a small part of my dinner qualifies as food," writes Alex F.
Exceptional Handling
Enterprise Resource Planning software, or ERP for short, is crucial to the operation of many large businesses. Several popular ERP systems have plugin-friendly architecture, the better to sell upgrades their customers will never want or use. This software is primarily aimed at businesses with too many complex process flows to manage by hand—making it the perfect domain for a small, lean startup with 3 developers and 1 customer.Ethan and Roland were brand-new developers, fresh out of college and ready to take on the world. Patrick, a consultant, was more experienced, though still fairly early in his career. They worked in C# with the Visual Studio ecosystem, and their boss had bestowed just one instruction as to how their culture should be formed:"Picture a scale from 1 to 10, with 1 being fast and 10 being scalability and code quality and all that crap. I want you to aim for a 2."Visual Studio is a great tool for beginning developers who need to work fast. It makes scaffolding the code simple and efficient, and allows for a drag-and-drop visual design that lets you rapidly prototype your screens. Couple that with great intellisense, and the team was confident they could deliver their addon as promised.That said, Visual Studio is also a complex piece of software, with many of its best features hidden inside a labyrinthine menu system and/or optional settings deep in a configuration file. It works better if you have time to learn how to use it. Unfortunately, our ERP team did not have that kind of time, and they missed a few key features. For example, out of the box, Visual Studio won't step into a catch block while debugging. You can debug catch blocks, but you have to explicitly set a breakpoint in them or they will be skipped entirely. There's an option to turn this behavior off, but it's hidden deep in the menus.Ethan and Roland developed a workaround for this behavior that let them continue working: they would comment out catch blocks surrounding code they were actively debugging, then restore the commented-out code afterward. But this took time and effort, and often multiple cuss-filled executions as they realized the exception was handled at a higher or lower level than they'd originally anticipated and they had to comment out more code. Finally, Patrick came up with a more creative solution: pre-emptively comment out all try-catch blocks in the entire solution, and stop adding more."There's no time for exception handling," he scoffed. "We have to move fast or we won't hit our street date."Ethan was concerned by this solution. He'd already caught himself forgetting to un-comment catch blocks using their old strategy. Wasn't this infinitely more risky? And how would they know their catch blocks were written correctly? What about testing the error messages they were meant to display to the users? Still, he was brand new, and Patrick had industry experience, so he was overruled.The weeks wore on, and development moved at blazing speed. The developers did their own unit tests, and from time to time, their BA would perform manual tests of the addon installed in the ERP system. It mostly crashed, but it was early yet. There was time to figure it out. Still, blazing isn't quite lightspeed, and the BA kept finding more and more crucial functionality that would be required if anyone was going to be interested in purchasing the thing. The general feeling of the project team matched the immortal words of Sonic the Hedgehog: "We're not going to make it. Let's speed up!"The team took on more developers in an effort to increase overall velocity. One of these was Alex, a contractor with 30 years of experience handling IT projects. Alex rapidly emerged as the clear leader of the entire team; his age and experience dethroned even Patrick. He spent increasing amounts of time sequestered with the boss, talking through everything from planned features to plugin architecture to the speed of development, which the boss felt was responsible for their missed milestones. Not because the code quality was crappy and therefore more time was spent fixing bugs, but because developers "weren't coding fast enough."The codebase had grown from a few hundred lines to several thousand. Ethan had found the magic toggle for Visual Studio that made it step into catch blocks, much to his relief. He reported this to the boss, and the ban on exception handling was (begrudgingly) lifted. Ethan adjusted rapidly, but many of the other developers still blamed exception handling for the slowness of coding. Often the addon would crash due to an incorrect cast or bad index. However, handling exceptions was seen as wasted time, so many developers refused to do it.Upon overhearing the boss and Alex discussing the matter, Ethan threw in his two cents. "We're nearing release. We should really start adding exception handling to all new code. Then we should do a final round of testing to make sure nothing breaks."This didn't go over well with the boss. The solution was simple to him. "Just don't use any exception handling. Remove all of it. Then we won't have to test anything extra, and we might even make our deadline."Ethan, after retrieving his jaw from the floor, protested violently. "Who's gonna pay for a system that crashes the moment you look at it wrong? What about data integrity? If bad data is persisted to the database, it'll fill up with garbage—and then the application will throw even more exceptions!""I know it's not ideal," said the boss, "but there's no time. Remember the scale: we need to be at a 2, and you're at like a 6 right now. This is industry standard stuff. Trust me on this, okay?"Time marched on. The company doubled in size, adding more developers who were forbidden from using exception handling. They moved even faster now, approaching the final ship date—well, the new final ship date, anyway.One day, while debugging, Ethan noticed that the addon didn't crash anymore, but did log an error to the console. "Wait, what? Where was that handled?"Concerned, he dug through the code. Most of his exception handling had been removed or commented out; he couldn't find a single catch block in the whole module he was working on. Finally, he found it: at the very top level, someone had put a try-catch block around the entry point to swallow any exceptions that were thrown.Ethan asked Alex about it the next time he caught him in the hallway."Yeah, we can't have the addon crashing all the time, you know?" Alex shrugged.Another junior developer poked his head out of a nearby cubicle. "It turns out, in C#, if you have an exception, the entire application crashes! Crazy, right? I found that out last week, and I told Alex about it, so we decided to implement exception handling."Ethan had no words at first. He just cradled his forehead in the palm of his hand. Finally, he tried one last time to explain. "Look. Exception handling is a good idea. But this is going to swallow all the errors, so debugging will be impossible. At the very least, let's put a catch block around each module so we know which one failed. And stop removing my catch blocks!"Alex shook his head. "You just have to do it right. All of you," he added, raising his voice so the others could hear. "If you just code it right from the start, there won't be exceptions, and handling them won't be necessary!"Ethan learned a valuable lesson that day: why exactly it was that startup developers tended to congregate in bars and debate the merits of various fine liquors online. It wasn't that people who liked alcohol were drawn to software development. Working at places like this drove developers to drink. [Advertisement] Universal Package Manager - ProGet easily integrates with your favorite Continuous Integration and Build Tools, acting as the central hub to all your essential components. Learn more today!
CodeSOD: Repeat Delete
Once upon a time, a client contacted Trick R. and asked him to figure out why files were disappearing from their website.The seemingly innocent task proved to be a swan-dive into a sewer of bad PHP, unsanitized user input, and plain-text passwords stored in the database, among other vulnerabilities. However, the following conditional took the cake for awfulness. What better way to ensure a record is really gone than by running the DELETE query a bunch of times?
A SNOBOL's Chance
We’ve all inherited legacy systems. You know the sort; 20 years old, more than 50,000 lines of code, poorly designed - even for its time, completely undocumented externally and useless code comments within, mangled beyond recognition due to countless developers making myriad ad-hoc changes upon changes and so-on. Now imagine such a system written in a tool that’s been around for nearly half a century, but rarely used for the intended purpose of the application.Reg worked for a firm that built space-rocket related applications; specifically an Ada compiler, written in SNOBOL, for a 15+ years obsolete legacy processor used in the rocket. The system itself consisted of more than 100 SPITBOL (a speedier compiler of SNOBOL) programs, most of which were written by one guy nearly four decades ago, Barry. Barry was a former sixties hippie-turned-coder. Though long since retired, he had been called back to active duty to try and help decipher what this thing does.The code is full of comments explaining what each block does, but not why. Nor were the comments up to date with what the code actually did, which was one set of “bugs”, in addition to the more normal set of errors. Of course, in those days, nobody wrote unit tests (was it even possible to write test suites for SNOBOL?) Some of the more interesting phenomena included mangled memory addresses, incorrect hex/decimal conversions, offsets disappearing, seemingly random mangling/unmangling/remangling of variable names, etc.Reg’s ongoing project was to replace this mess with a shiny new Ada compiler written in Python.Along the way, Reg had to deal with all the control flow of SNOBOL (e.g.: goto’s), on-the-fly execution of strings containing arbitrary SNOBOL code, the immediate-value-assignment operators (‘.’ and ‘$’) and pattern matching that would reduce a regex-wizard to a quivering mass of Jello.Even Barry, the tie-dyed, retired, hippie could no longer decipher what the internals were doing. Maybe he’d just fried too many neurons. Reg couldn’t get any further- maybe he just wasn’t smoking enough marijuana to understand what the hippie had done. Reg decided to simply try to replicate the output of the legacy system. This was accomplished by running both systems on the same input and doing diffs.This project started long before Reg joined the firm, and will probably be going strong long after he’s gone.Reg got the number of diffs on the output down to less than 1,000. That might not sound great, but almost all of them were caused by bugs in the legacy code.Now his toughest job begins: explaining to management why success must be defined as about 1,000 differences in the output between the legacy and replacement systems, and, more importantly, determining whether correcting the output of the previous systems will cause the rocket to act in an undesirable manner. Like exploding.[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: A Type of Test
Unit tests are a wonderful tool for proving that your code works. Ideally, when you’re using other code, like say, the .NET Framework, you don’t write tests that test the framework itself. After all, didn’t Microsoft already do that?David T’s co-worker laughs at your naïveté. Why would you trust Microsoft? You need to make sure the framework works as advertised. Which is why their unit tests are mostly made up of code like this:
Error'd: "X" Marks the Spot
Dan writes, "This happened when selecting 'see more' under my (Your) recommendations. Maybe there's buried treasure somewhere?"
The World Tree
When Nate was wrapping up his senior year of college, he hunted around for a job that would hire an undergrad on flexible hours. He knew that the kinds of companies that tended to hire on those terms could often have… creative practices, but college wasn’t about to pay for itself.He found a small shop that needed an extra hand. Extremely small- there was only one other developer, Gordon. Nate was prepared to enter a tiny shop with no real practices or procedures, because with only one developer, you don’t expect a lot of rules and bureaucracy.Gordon was only one person, but he was able to create enough contrived, arcane, and downright mysterious bureaucratic policies and procedures for fifty developers. Reading the style-guide was closer to reading a novel, but not a good novel where there was a clear point and narrative thread, but something meandering and pointless, like a Douglas Adams book.Gordon wasn’t just opinionated about style. He also had Opinions™ on the proper use of source control. “Branches,” Gordon explained, “are absolutely vital for separating units of work.”Gordon’s explanation came after Nate was stunned by the sheer number of branches- there were hundreds of branches in the repository. “Look,” Gordon said, “you don’t have to be intimidated by this. We can start you out, just do this small change in the main branch, then I’ll show you how to release it.”Nate dutifully checked out master, made the change, and committed it. He sent Gordon a pull request.“You used the wrong branch. Back out your change, and put it in the main one.”“Which branch is the main one? It’s not master?”“It used to be, but we don’t really use master anymore. Use master_4513.”As it turned out, the “main branch” was usually whichever branch Gordon touched last. There were five or six different branches that could be the “main” branch at any given time. Maybe seven- it was very hard for Nate to be certain.Nate made the changes in master_4513, but that was only the start of the nightmare. Now, those changes had to be merged into the correct branch for deployment. “This is pretty complex, do you want me to walk you through it?” Gordon asked.Nate said yes, and so Gordon sat down next to him, and started explaining each step that Nate needed to perform. These “explanations” started with Gordon pressing his fingers against Nate’s monitor and saying, “Click here.” “No, fire up the GUI, not the CLI.” “Select this branch.” The instructional process was recorded as a smear of fingerprints on Nate’s screen.Changes merged outward from the main branch (whatever “main” happened to be that day). Instead of merging back towards a known-good trunk of code, changes were made to the trunk, and then percolated outward, according to Gordon’s own twisted logic. “You see,” he explained, “we’ve gotta maintain, like, 15 different versions, and some of them depend on a different version of our framework lib. This main version builds against version 1.2 of the framework.”“But… isn’t your framework up to version 4.5? Like… for years now?”“Yeah, but this change only goes out to the 2.0 users, so you need to merge from main to master_51, then to frameworkupgradeA1, then to perky_peregrine. You’ll need to resolve conflicts.”Nate ground his teeth hard enough to make diamonds between them, and fought his way through the merge conflicts. A few hours later, Nate’s one line change was merged into a releasable version, but Nate had no idea how that change would migrate to any other version, if it ever did.Nate’s next assignment was to make a change to the same version, and since it was a larger change, he made a feature branch off of perky_peregrine, do the changes there, then merge right back into perky_peregrine after the work was done. Then he could propagate the changes back to the current “main” branch, asdfg. This resulted in an angry visit from Gordon.“Are you trying to mess this up?” Gordon demanded. “There is a system. There are policies! Did you even read the development guide I gave you? Feature branches are fine, but they have to come off the main branch, not one of the dependent branches!”Nate had tried valiantly to read it, but failed. “I was just going to do the work, merge into perky_peregrine, and then delete the branch, why does it matter?”“Merge back?” Gordon shrieked. “DELETE the BRANCH? Branches don’t merge backwards, only outwards. Like a tree. Each feature branch is supposed to be an entirely new line of development. Have you even used source control?”Something snapped in the back of Nate’s brain, because for a brief, terrifying moment, that almost made sense. Nate had been puzzling over the bizarre state of their source control repository, and those words from Gordon put understanding it within tantalizing reach. If he asked a few more questions, he might just see the method to this madness…Nate chose the wiser path. He smiled, he nodded, he complied with Gordon’s policies, and moved on to the next feature, weeks after cutting through the shrubbery that was Gordon’s branching system.The next feature was to make a change that only impacted users of the latest version of the base framework. The current “main” branch was back on version 2.3, so Nate needed to start by making a branch from there. Then he had to bring it up to version 4.0, then convert a few of the datafiles into a new format, then finish the upgrade to 4.5. This was about two weeks of hair pulling frustration. Then he could make his changes. He spent that week asking serious questions about the career path he was on. Finally, he could merge his changes into the actual 4.5 release branch, but never back into any master branch.This resulted in tens of thousands of merge conflicts. The next few weeks were spent cutting through them, and by the end of that time, Nate discovered the semester was nearly over. He was about to graduate. He went to Lindsey, the co-owner of the small company, and handed in his resignation.“We’ve been really impressed by your work,” she said. “You could stay on after college, if you like.”Her tone was even, perhaps even a little indifferent, but there was a plea in her eyes. Nate vaguely recalled hearing that Gordon was a friend of Reggie, the other co-owner. Nate saw a hint that Lindsay knew what Gordon was doing to their software product. Maybe she thought Nate could be her ally in fixing it.Or maybe Nate was reading too much into it. Discretion was the better part of valor. “I’m sorry, I just don’t think I’m the right fit for this team,” he said. They made the polite noises, she promised him a recommendation letter, they connected on LinkedIn, and Nate went off to find a source tree that didn’t look like a tangled briar.A few months after Nate settled into his new job, he snooped on Gordon’s LinkedIn profile- he was unemployed. A message to Lindsay confirmed that she’d fired him over his inability to deliver new features. The last anyone had heard, Gordon had retired to a cabin in the woods, where he could be alone with many branches that never merged back into their trunks.Editors Note: We meant no harm in teasing Douglas Adams, but your reaction was much more interesting than it would have been to another tired Twilight joke.
CodeSOD: Dollar Dollar Dollar Dollar Underscore
An Anonymous source sends us some Java code they found in source control, with really special variable naming conventions. I can only assume this came from a plucky startup hoping to attract venture capital.
No Account for You
Ed wasn’t excited about his job. He worked for a large automotive manufacturer. This is the kind of industry that might invest heavily into robots and research and development, but when it comes to managing their supply chain and accounts receivable, their IT infrastructure was frozen in amber circa 1974.The pay was fine, but the work was frustrating. Things like “Code reviews” and “refactoring” were viewed as “wastes of time” or “developers playing with toys”. Unit tests were a luxury for “lazy” developers- good developers should just be writing code that works. If the work you’re doing isn’t directly involved in getting cars built and shipped, you shouldn’t be doing it.Ed was looking to get out of the company, and while he kept sending out resumes, he found more excuses to get away from his desk by taking smoke breaks with Mitchell. Mitchell was a lifer- he joined the company back when pensions were a thing, and was close enough to retirement that he just needed to keep his head down and stay the course to check out with a nice nest-egg. “But you,” he’d tell Ed, “you’ve gotta get out of here. You’re young. You shouldn’t be wasting your time here.”After one of those smoke breaks, Ed returned to his desk to see Pilar waiting for him. Pilar was their summer intern, a junior in college. She mostly handled “manual reporting”, which was a euphemism for “we don’t actually have a reporting system for this data set, so we have an intern run SQL queries against production and then copy/paste the results into a spreadsheet.” Yes, there were still manual reports because none of the SBUs wanted to pay to automate them.“I’ve got a new report,” she said, “and it’s on something called SCORDBE? You wouldn’t know how I get access, would you?”Ed didn’t know. At best, he might have seen the acronym someplace on a PowerPoint during a quarterly meeting once. “No, but has anyone shown you the Internal Apps Sheet?” He was referencing a spreadsheet used to track support contacts for different applications. He CTRL+F-ed to the entry for SCORDBE. “Oh, no…”The SCORDBE database was administered by Yev “Ticket-Nazi” Kassem. He automatically closed any tickets for changing the database- even for production releases. Any ticket requesting access to the database, for any reason, received a simple reply: “NO ACCOUNT FOR YOU.” He used IP whitelists to prevent connections from unapproved devices. While it probably was good for security, that was an afterthought. Yev had a small bit of power, and he wanted to make sure that he held onto it.Still, that was just the database side. There was an application on top of that database. He scrolled across the spreadsheet, past the cloumns for “Approving Manager”, “SBU Contact”, “SBU Backup Contact”, “SBU Backup Bakcup Contact” and found “IT Development Contact”. It was Mitchell.“I don’t think you’ll get very far with the database,” Ed said. “But maybe Mitchell can help?”Pilar went off to visit Mitchell, and Ed got back to his regular work. A half hour later, Mitchell CCed him on an email to Pilar. “I’ve got a solution. Just visit this URL and it’ll run your query. And you can change the id=… part at the end to do it for other part numbers.”Ed didn’t think much about it until his next smoke break. “So,” he said, “how’d you get past the Ticket-Nazi?”Mitchell laughed. “I didn’t.” He paused and lit his cigarette, taking a few drags before explaining. “SCORDBE is about 35,000 lines of Perl written back in the 90s. Nobody ever wants to touch this code, and nobody really understands what it does. I figured there had to be some poorly escaped queries, so I just grepped until I found one. Now we can run ad-hoc queries as needed.”Ed left the company a short time later. Mitchell, and his injection-based reporting solution, however, are still there. [Advertisement] BuildMaster integrates with an ever-growing list of tools to automate and facilitate everything from continuous integration to database change scripts to production deployments. Interested? Learn more about BuildMaster!
CodeSOD: The Wisdom of the Ancients
As Halloween descends upon us, mysterious emails start reaching our inbox. These plaintive missives are but the screams of the damned, encoded and sent over SMTP.For example, someone known to us only as DBA Guy sent an email with this subject: “Silver bullet SQL scalar function built by the Ancient Ones”.These ancient ones obviously did not come from the Euclidian plane we know so well, but obviously from a twisted, higher dimensional space where there exist no right angles.The code itself, is simple:
Error'd: Going Fast
"This building is sinking so fast that it lost 4 floors between the headline and the body," writes Hans.
Deep Fried Offshore
Stephen worked for an Initech that sold specialized hardware: high-performance, high-throughput systems for complex data processing tasks in the enterprise world, sold at exorbitant enterprise prices. Once deployed, these systems were configured via a management app that exposed an HTTP interface, just like any consumer-grade router or Wi-Fi access point that is configurable through a website (e.g. 192.168.0.1).Stephen worked with a diverse team of American engineers who were finishing up the management application for a new model. The product was basically done but needed a little bit of testing and polish before the official release. They expected several months of post-release work and then the project would go into maintenance mode.Then disaster struck. A pointy-haired boss somewhere up in a fuzzy area of the organization chart simply labeled “Here be VPs” discovered the large salary difference between American engineers and off-shore workers, and decided American engineers were far too expensive for software “maintenance”. The company decided to lay off 300 software engineers and hire 300 fresh-out-of-college replacements in a foreign country with much lower labor rates. The announcement was overshadowed by the fanfare of the product’s release and proudly billed as a major “win” for the company.Stephen was lucky enough to stay on and shift to other projects, the first of which was to assist with the transition by documenting everything he could for the new team. Which he did, in hundreds of pages of explicit detail, explaining how to use the source control repository for the project, execute and log unit tests, and who to contact when they had questions regarding the hardware itself. After that, he devoted himself to other projects. Months turned into years and Stephen assumed by the silence that the handover was successful and he’d never see the management app again.Of course that isn’t what happened.There’s an old joke on the Internet called “How to shoot yourself in the foot” (http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html) that lampoons the complicated process of shooting yourself in the foot in various programming languages. Here is one such entry:
CodeSOD: data-wheel="reinvented"
In HTML5, the data-* attributes were codified, and this is a really nice thing for building applications. They are an app-defined namespace to attach any sorts of custom data to your HTML attributes. For example, a div responsible for displaying a User object might have an attribute like <div data-user-id="5123">…</div>, which allows us to better bind our DOM to our application model. They can even be used in stylesheet selectors, so I could make a styling rule for div[data-user-id].I’m not the only one who thinks they’re a nice feature. Eric W has a co-worker who’s come up with a very… unique way of using them. First, he has the following Django template:
Test Overflow
WidCo was a victim of its own success. It had started as a small purveyor of widgets: assembling, storing, transporting, and shipping the widgets to their small client base in their podunk state. They'd once had the staff to fill orders placed by phone. As they'd begun to make a name for themselves in the surrounding tri-state region, however, their CEO had caught wise to the value of "this Internet thing."Within a decade, they were not only the country's foremost producer of widgets, but their entire staff makeup had changed. They now had more employees in IT than the other departments combined, and relied on in-house software to manage inventory, take orders, and fulfill them in a timely fashion. If the software went down, they could no longer fall back on a manual process.And—as the IT manager was fond of pointing out in budget meetings—they had a QA department of 0 and no automated tests.Bug reports piled up. Who had time to fix bugs? Monday was for scrambling to remedy production incidents after the weekend's jobs ran, Tuesday was for slapping together something sensible out of requirements documents, Wednesday for coding, Thursday for manual testing, and Friday for shoving half-tested code into production. Agile!Finally, over the post-Christmas slump, the IT manager managed to convince the CTO to bring in a trainer to teach developers about "improving our unit tests". All 0 of them.Adding tests to existing code was deemed a waste of time. It compiles, therefore it works. Begrudgingly, the CTO admitted that unit tests might be a good idea for new applications. Sometime in the next decade, they were bound to build a new application. They'd do this testing thing then.Desperate, the IT manager put in place a code review policy: before anything could be deployed, someone had to look at it. But they were checking only the changes, the CTO pointed out. It was a waste of time to examine working code in production. Standards were seen as just documentation, and documentation was waste. Look at the existing code and do more of that."Think lean," the CTO said.The IT manager sighed and hung his head.And then a lucrative new contract was signed: WidCo would be selling widgets in Canada as well. When their distribution partner expressed concern about the lack of a QA department, the CTO loudly proclaimed that all their developers had QA training, and they were bringing in an engineer to streamline the testing process. A position promptly opened under the IT manager, who was seen with an actual, honest-to-God smile on his face for the first time all year.Interview after interview was conducted. The first engineer was a bright young chap, a brunet with an easy smile and big round glasses. He started on a Tuesday, bringing in donuts to share with the team and promising to have things cleaned up within the week.Two days later, he handed in his resignation, crawled into a bottle, and refused to answer his phone, muttering about raw pointers and RAII. Later, the team found him waiting tables at the local pub, his bright smile turned into a sullen sneer.The second QA engineer was made of sterner stuff. She had the benefit of already being familiar with the code: she'd been brought in as a development contractor to save a project that was running over deadline earlier that year, and while she hadn't managed to work a miracle, she did impress the IT manager.By now, the CTO was so over the whole QA engineer thing. He was onto this newfangled "DTAP" standard, declaring that he'd stand up a Development server, a Test server, an Acceptance server, and a Production server, and all code would be promoted between them instead of going right from the developers' machines to prod.And so the QA Engineer rolled up her sleeves and tried to develop a sane promotions process. She set up an instance of Subversion and stuffed all the code into it. In order to comply with the standard, she made four branches: Dev, QA, Acceptance, and Trunk. Code would be done in dev, merged into QA for testing, merged into Acceptance for acceptance testing, and merged into Production to deploy. A daily cron job would push the code onto each server automatically. Continuous Integration!The build system complete, she could get to her main job: testing code on the Testing server. She sat the project managers in a room and explained how to test on the Acceptance server. Within a month, however, she was doing it for them instead.At least we're testing, she told herself, resigned to switching hats between "Try to break it" mode and "Is it actually nice to use?" mode when she changed servers.Of course, there were 30 developers and only 1 QA engineer, so she didn't have time to go through changes one by one. Instead, she'd test a batch of them on a weekly schedule. But by the time they were merged together and pushed to the servers, she had no idea which change was responsible for a test failing. So all the tickets in that batch would have to be failed, and the whole thing reverted back to the dev branch. Sometimes multiple times per batch.It was getting better, though. Every batch had fewer issues. Every code review had fewer comments. The QA engineer was beginning to see the light at the end of the tunnel. Maybe this would get to be so low-key she could handle it. Maybe she'd even be rewarded for her herculean efforts. Maybe she'd get a second helper. Maybe things would be okay.Then the CTO read an article about how some big-name companies had "staging servers," and declared that they ought to have one to improve quality. After code was accepted, code would then be deployed to the staging server for a round of regression testing before it could go live. Of course, since they had a dedicated tester, that'd simply be her responsibility.On the way out of that meeting, her heart sinking, the QA engineer was stopped in the hall by a project manager. "We've noticed a lot of tickets are failing," he began with a stern look. "That looks bad on our reports, so we're going to be running an extra round of testing on the dev server before it gets to you.""Oh, good, so maybe there'll be less tickets I have to send back," she said, raking a hand through her hair."Exactly," he said with a hint of a smile. "I'll forward the invite to you so you can sit in and give your feedback. It'll be 4 hours on Monday afternoon."Her efforts to weasel out of it were to no avail. She was the QA expert, after all, and her job was to train anyone who needed training. Henceforth, code would be checked into dev, tested by the project management group and the QA Engineer, moved to QA, checked by the QA Engineer, moved to Acceptance, checked by the QA Engineer, moved to Staging, checked by the QA Engineer, and then finally moved into production.After a few failure cycles in QA (somehow, the project managers weren't very effective at finding bugs), she was staying late into the evening on Friday nights, testing code as fast as possible so it could go to production before it was technically Saturday and thus overdue.Of course, because only she knew when the code was ready to move, the QA Engineer found herself in charge of merging between branches. And she had no idea what the code even did anymore. She never got to work with it, only seeing things from the UI level. And she was usually exhausted when she had to merge things. So there began to be a new class of error: merge errors, introduced by sloppy testers.The CTO had a brillant solution to that as well. He split up the shared libraries, making multiple copies of the repository. Each team would have their own stack of DTASP servers and their own version of source code. That way, they could deploy without having to merge code belonging to different teams. In addition to their existing separate dev instances, all 10 3-man teams would get 8 servers each: test, acceptance, staging, and prod, plus a database for each. And the QA engineer would have to test all of them.These efforts failed to make a dent in WidCo's bug backlog. However, the QA engineer made a killing running a betting pool in the breakroom. The odds were calculated fresh every Monday morning, and the payout went out when metrics were pulled on Friday afternoon. There was only one question to gamble on.Which was larger this week: the average time required to deploy a fix, or the average time for a developer to leave for a new job? [Advertisement] Incrementally adopt DevOps best practices with BuildMaster, ProGet and Otter, creating a robust, secure, scalable, and reliable DevOps toolchain.
CodeSOD: Keeping it Regular
Regular expressions are like one of those multi-tools: they're a knife, they're a screwdriver, they're pliers, and there's a pair of tweezers stuck in the handle. We can use them to do anything.For example, Linda inherited a site that counted up and down votes, like Reddit, implemented in CoffeeScript. Instead of using variables or extracting the text from the DOM, this code brought regular expressions to bear.
Error'd: The Duke of Error'd
"Ok, so what happens if I'm a duke? Then what?" wrote Adam S.
The Contractor
As developers, we often find ourselves working in stupid ways because the folks who were hired above/before us think that what they set up is ideal. While this happens in numerous industries, finance, especially at huge conglomerates, takes IT/Software-WTF to a whole new level. As contractors, we often get the we need your help in an emergency even though everything is unicorns and rainbows speech that precedes some meltdown for which they want you to take the blame.After taking a contract position at a large financial company, Bryan T. expected to see some amazing things. On the interview, they talked a big game and had even bigger budgets. It didn't take long to see some amazing things; but not the kind of amazing you'd think.To begin with, the managers and developers were still trying to roll their own time zones and caching. They didn't understand any of these terms: object graph, business intelligence services, concurrency, message pump, domain model, and well-defined. Bryan even needed to explain to them why JavaScript on random web pages doesn't have natural mechanisms to attach to .NET event handlers in other applications.Their head DBA explained that the difference between a uniqueness constraint and a primary key was semantics, and that audit records and current records should always be stored in the same table so as to keep related data together. They even used a simple text column to store City, State and Country, which led to obvious issues like three different values for the US ("US", "USA", "US_TOTAL").We all need to conform to some semblance of coding practices. These folks decided to use anti-coding-practices. For example, IEntity was a class but the "I" prefix was used because it was returned from an API.Shared common libraries were not allowed; if you needed to re-use a chunk of code, copy and paste it to where you need it; that's why they implemented cut-n-paste across applications!This also explains why SLOC is their primary productivity metric.There were no planned releases or scheduled iterations; whenever someone barked, a snapshot was manually copied from local builds.Perhaps most interesting of all, they had an awesome approach to branching. Instead of actually branching, they copied the whole code base into a new repository and ran that forward. Of course, this left a trail of repository droppings that you had to navigate.It took Bryan quite a while to acclimate to all of this. Then the team received a massive product request. Unfortunately, nobody understood the concept of scalability, let alone why it had to be considered. Instead, they decided that Cowboy Coding would be the M.O. of the project.At this point, Bryan decided he didn't want the job all that much. That very day, he had to work with another developer with whom he'd not yet had the pleasure. Their task was to return some JSON from a web service call. After more than a month of work, the other developer proudly showed Bryan what he had come up with to return specific data from the web service:
CodeSOD: Work Items Incomplete
Owen J picked up a ticket complaining that users were not seeing all of their work items. Now, these particular “work items” weren’t merely project tasks, but vital for regulatory compliance. We’re talking the kinds of regulations that have the words “criminal penalties” attached to them.What made it even more odd was that only one user was complaining. The user knew it was odd, their ticket even said, “Other people in my department aren’t having this issue, so maybe it’s something with my account?” Owen quickly eliminated their account as a likely source of the problem, but Owen also couldn’t duplicate the bug in test.A quick check showed him that the big difference between test and production was the number of work items. With a few experiments, Owen was able to trigger an infinite loop, when the number was very low. He dove into the code.
...38394041424344454647...