Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

Jul 2014

The Joys of Interdisciplinary Work

by in CodeSOD on

Lisa thought that the Modesto Biology Institute was the perfect working environment. The scientists who showed her around were all friendly, not the "evil, lab-coated villains" portrayed in Fritz Lang films. The lab director, Howard, pointed out the lack of horror monsters in their lab after Lisa joked about it during her interview.

"See?" Howard said, gesturing. "You won't find anything scarier than a petri dish in here ... except for grant applications." He looked disgusted at the suggestion.


A Team of One

by in CodeSOD on

Bob worked at a small company. There’s a messy history in its founding. The owner, Aaron, worked for another company making basically the same software, until he finally got fed up with their coding style and practices. So he quit to found his own company, with his own rules about things, like how many blank lines there should be before a for loop (exactly 1), how to order variable declarations (alphabetically, with “::” coming after “z”), and how source control should be organized (about as organized as organized crime).

Aaron didn’t waste a lot of time managing, and made sure to keep his hands in the code. Of course, no one wanted to touch the code after he did, which meant Aaron wasn’t just the owner, but he was a one-man team. The other teams might deliver features, but Aaron’s team delivered vision. Well, vision, and code blocks like this, which parse parameters off the command-line:


Doing a Split...the Hard Way

by in CodeSOD on

Way back when Java first came out, if you wanted to split a string into tokens, you had to roll your own mechanism to do so. Of course, even as far back as Java 1.2, there were some built-in secrets to help you tokenize your string so you could iterate over the tokens.

David S. found this little gem written by one of his cohorts in a very recent version of Java (which we all know has absolutely no way of splitting a string into tokens).


An Odd Way to Find Even Numbers

by in CodeSOD on

Fred S. never much cared for zebra striping, the UI pattern that was all the rage after Mac OS X launched in 2001. It found its way into other Mac applications, web pages, even onto Linux. Like a tsunami of alternating grey-and-white waves, it overtook everything in its path.

After numerous requests from users, the project manager for WeightTracker asked Fred to add zebra striping to the weight journal window. Fred had inherited oversight of the application after the original developer, Louis, had been poached by their underperforming rival.


State of the UNION

by in CodeSOD on

Correct now, optimize later. is one of the most important developer mantras and Scott K. followed it to a fault. He was on a team of programmers debugging a C# package management application, which used Microsoft SQL for revision tracking. Make sure it works right the first time; you can always tease out more performance after launch.

But if your program takes ten minutes to extract a C# package, as Scott discovered, you might want to optimize sooner rather than later.


Sound and Fury, Implementing Nothing

by in CodeSOD on

Mark was upset. You didn't have to sit next to him to know it, either. Even though his cubicle was at the far end of the farm, his frequent tirades were always audible to the rest of the office. Mark wasn't the most skilled or the most careful developer on the team, but what he lacked in ability he made up for in volume: a lot of his poorer decisions stood simply because his colleagues wanted to avoid a barrage.

The installer for their main product was Mark's pride and joy, so Jonathan tried to stay as far from the code as possible. Mark had long ago added a timeout to the code that checked for a stuck installation, but it consistently went off too early, complaining about failure when the installation would eventually succeed. When Mark tired of the QA team complaining, Jonathan overheard him bellowing at the team lead.


Code Abuse

by in CodeSOD on

A client of Jim's with a WordPress site had been having performance issues that were off the scale bad. Slower then a snail on Valium. Slower than a herd of turtles rampaging through a molasses factory. Worse than that, the actual in-browser rendering was taking significantly longer than any benchmarking tests would lead you to believe. Even massively loaded benchmark tests had a better rendering time. And the client's browser's weren't massively loaded.

After investigating a number of avenues, Jim decided to migrate the site to newer, faster infrastructure. The older machines were due for a refresh anyway. And the newer infrastructure would be on Ubuntu Precise, whereas the older was Lucid. So, as a bonus, the client got a free upgrade! Free as in beer.