Recent Articles

Jun 2021

Repository, Man

by in CodeSOD on

C++ templates are, notoriously, a Turing complete language on their own. They're complicated, even when you're trying to do something simple. Related languages avoid that complexity, and favor generics. Generics are templates with all the sharp bits filed down, but still powerful enough to make datastructures that don't need to know the details of the data they're operating on.

This article isn't about generics, though. It's about ORMs, specifically the .NET Entity Framework system. It's common to use the Repository Pattern to abstract out data access a bit. Coupled with the underlying DBSet class, which roughly represents a database table, you can easily create repository objects and related mocks for testing.

Big Number One

by in CodeSOD on

Patsy's company has a product that's "number one" in their particular industry. It generates lots of revenue, but a lot of the code dates back to the far-off year of… 2017. Coding practices were… uh… different, four years ago? Especially in the rapidly maturing language of… Java?

Within Patsy's company, they do refer to their 2017 code as "legacy" code, and it has left quite the legacy. For example, here's how they parse numbers:

Out of You and Umption

by in CodeSOD on

When we write code, we have certain assumptions. Most of these times, these assumptions are fine, and allow us to skip past some hard decisions. But sometimes, these can lead to problems. The infamous example would be the Y2K problem- the assumption that nobody'd be running this program in 40 years seemed reasonable at the time. We might assume that nobody'd type too fast. We might assume our sensor is accurate.

Darren sends us some code that has a much milder assumption than those:

Production Testing To The Max

by in Error'd on

The most eventful day in Error'dland narrowly missed our publication window last week. As everyone must surely know by now, somebody at HBO Max was testing in production. And the Internet blew up.


Classic WTF: The Mainframe Database

by in Feature Articles on
As our summer break continues, we tend to get nostalgic for summers past, for the way things used to be. Like they were back in the mainframe days. Wait, what? No, not that. Anything but that. Original --Remy

IBM System360 Mainframe

George, an independent contractor, usually spent his first day home from a business trip plowing through the emails that'd piled up in his absence. In the midst of this grind, he received a call from Lucinda, a Microsoft contact from South Africa.

Classic WTF: Front-Ahead Design

by in Feature Articles on
Summer breaks are a great opportunity to improve yourself. And what's a better way to use your summer break than to take some high end certification training. Prove that you're ready for the FAD! Original --Remy

In the past, I didn’t mix TDWTH and work too often, but with the tweaked name and tweaked direction on content, I knew this article would be a perfect fit.

As some of you know, I fill two important roles in my day job at Inedo, LLC. Not only am I a software developer, but I’m also the Chief Front-Ahead Design Evangelist. In this latter role, it’s my duty to spread and champion the revolutionary software development methodology known as Front Ahead Design (FAD).

Classic WTF: Gaming the System

by in Feature Articles on
Our summer break continues. For some people, summer means outdoor fun. If, like me, you hate sun and temperatures above "chilly", it can instead mean air-conditioned indoor fun. And it's all fun and games until someone loses their job. Original. -- Remy

Frank slammed his axe into his co-worker's skull. Ernest grunted and raised his double-barreled shotgun in reply. "Merry Christmas!" he shouted as he fired both barrels. Frank exploded into several gore-colored polygons.

"Jerk," Frank grumbled as he waited for his respawn. It was late Decemeber, 1997, an era of before thumb-drives and when Quake was the best deathmatch money could buy. Normally, such lunch-time and break-time violence was frowned upon, but it was the holidays. When most of the office is on vacation, and the people that aren't just need to keep the lights on and not make trouble, you can get away with those sorts of things, so long as you uninstall it after the New Year. They Quaked away through the holidays.

Classic WTF: The Great Code Spawn

by in CodeSOD on
We're taking a little summer break this week for our regular articles. Since we're re-using articles, let's start with one about developer efficiency. Why write code when you can automate writing code? Original -- Remy

Several years ago, Dan D’s predecessor, Steve, came to the realization that many of us arrived at one point or another: writing data-access code can get boring and repetitive. To ease the tedium, Steve did what many developers in his position do. He wrote some code to generate a lot of code.

Unfortunately, Steve’s coding skills weren’t all too hot. Worse were his code-writing-code writing skills. In the years since The Great Code Spawn (as it has come to be known), the data-access layer has become an unmaintainable disaster – so much so that, rather than add a new database column, developers have “split” single fields into multiple through bit-shifting and string manipulation.

Some Sunny Day

by in Error'd on

Filter Your Kwargs

by in CodeSOD on

Mark's team needed someone to write a pretty straight-forward report for their Python application. It would take a set of keyword arguments, turn those into a filter, apply the filter, and get the results back.

This was implemented in two methods. First:

World Class Contracting

by in CodeSOD on

The time and effort needed to complete a project and the amount of time available rarely line up well. Wayne M's company found themselves in a position where what they needed to deliver and what they could deliver by the deadline simply didn't match up.

The requirements were well specified, so they bundled up a bunch of requirements for search-related functionality, and handed them off to a self-described "world class" developer working on contract.

A Date With Yourself

by in CodeSOD on

Once upon a time, someone wanted to add a banner to a web page. They also wanted the banner to only appear after a certain date. Jack stumbled across their implementation when trying to understand why the banner would vanish for two weeks at the start of every month.

// get date var MyDate = new Date(); var MyDateString; MyDate.setDate(MyDate.getDate()); MyDateString = ('0' + MyDate.getDate()).slice(-2) + '-' + ('0' + (MyDate.getMonth()+1)).slice(-2) + '-' + MyDate.getFullYear(); if (MyDateString > '13-04-2014') { // do stuff... }

Experience is Integral

by in CodeSOD on

Behind every code WTF is a process WTF. For example, Charles W was recently tasked with updating some file-handling code to match changes in the underlying file-format it parses. This is the C code which parses an integer:

if ((*p == '-' || ('0' <= *p && '9' >= *p)) && retCode == -256) { retCode = 0; p = _tcsrev(p); if (*p == ' ') p++; for (i = 0; '0' <= *p && '9' >= *p; i++) { retCode += (int)pow(10, (double)i) * ((int)*p - 0x30); p++; } if (*p == '-') retCode *= -1; }


by in Error'd on

It's been quite a few years since I was last in Silicon Valley. So it wouldn't surprise me at all if some enterprising restaurateur has unveiled a trendy pub and stolen all the humorous thunder from Sean's submission. I'll be more surprised if they haven't.

Quite the Event

by in CodeSOD on

A few years back, Alvin was in college, and took his first formal summer job as a programmer. It was supposed to be just some HTML layout work, and the designer handed him a few sample pages. "Just do it like this."

The "sample pages" were a mishmash of random indentation, huge swathes of commented out code, and all those other little traits of "someone's just coding in production, aren't they?" that crop up in files. Still, it was just some HTML layout work, so how hard could it be?

Getting Overloaded With Details

by in CodeSOD on

Operator overloading is one of those "dangerous" features. Like multi-parent inheritance, it can potentially create some really expressive, easy to read code, or it can create a disaster of incomprehensible nonsense.

In C++, many core classes use operator overloading, most notably the I/O classes, which reuse (or abuse) the bitshift operators into stream operators. So, for example, one possible way of converting a string into an integer might be to do something like this:

Contractor Management System

by in CodeSOD on

Maximillion was hired to maintain a PHP CMS. His new employer, up to this point, had just been contracting out work, but as time went on, contracting rates got higher, the amount of time required to add basic features kept going up. It was time to go ta a full time employee.

"The system's pretty simple," the hiring manager explained during the interview, "as I understand it, it's basically just one PHP file."

Are You Active Enough?

by in CodeSOD on

Cornelius was working with some code where the objects might be "active" or "inactive". His code needed to do something different, depending on whether the objects were "active" or not, but fortunately, there was a handy-dandy IsActive method. Weirdly, that method required a bool parameter, but also returned a bool. Since there wasn't any useful documentation, Cornelius checked the C++ code.

bool SomeActivatedClass::IsActive(bool& active) { active = true; return false; }

Scratch and Dent

by in Error'd on

A Little Info

by in CodeSOD on

Matt has plans for the next few years: dealing with the "inheritance" of some legacy systems.

They're written in VB.Net, which isn't itself a problem, but the code quality leaves just a bit to be desired.

A World Class Programmer

by in CodeSOD on

Jesse had a "special" co-worker, Rupert. Rupert was the sort of person that thinks they're the smartest person walking the Earth today, and was quite happy to loudly proclaim that everyone else is wrong. Rupert was happy so long as everyone else was ready to bask in his "genius".

Fortunately for Jesse, Rupert left, because he'd received a huge offer for a senior developer role at a different company. Everyone at Jesse's company privately chuckled about it, because this is the kind of code Rupert's genius produced:

As Authentic as it Gets

by in CodeSOD on

Virginia N (previously) needed to maintain some authentication logic. The actual rules for authentication weren't actually documented, so her choices were to either copy/paste some authentication code from a different project, or try and refactor the authentication method in this one.

It was a hard choice. We'll dump the whole block of code, but I want to pull out a few highlights, starting with the opening condition: