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.

Apr 2009

Stupid Coding Tricks: XSLT Mandelbrot

by in CodeSOD on

Welcome to the third installment of stupid coding tricks! As we learned from the T-SQL Mandelbrot and A Batch of Pi, stupid coding tricks aren't really about obfuscation per se... just, well, stupid awesomeness. Kinda like a quine, except even more useless.Got a trick of your own? I'd love to see it, so send it on in.

If you were to use The Daily WTF as a guide, your impression of XSL Transformations (XSLT) would probably be fairly low. I mean, seeing article after article after article might have given the impression that XSLT is often not the right tool for the job... or, perhaps, maybe not even a right tool. Period.


Fred Code

by in CodeSOD on

Bruce got an urgent phone call from the Boss: one of the Big Customers was having some trouble with a system Bruce's company built, and it needed to be fixed right away. The application in question was the back-end for a wireless inventory management system and was responsible for maintaining the status of each location in the store in a flat text file.

Over the years, the application had been maintained by a contract programmer named "Fred" who had quite a few "nonstandard approaches" to application development. Being a contractor, his income was dependent on getting more contracts when the current contracts expired. His didn't accomplish this by writing good-quality code as to get repeat work and recommendations. Instead, he wrote code so awful that his victims would have no choice but to call on him to fix up the mess. Fred also had a background in COBOL programming, and it showed in his C code.


zzGeneralFunctions

by in CodeSOD on

A codefile whose name is prefixed with “zz” can be one of two things. It's either a file that someone wanted to get rid of but was afraid to delete, or it's an intentional naming scheme to keep the file at the bottom as part of some crude code-organization technique. There used to be a third option - the file's a part of an application commissioned by a certain American rock trio known for their beards and cheap sunglasses - but the band dropped that requirement a long time ago.

However, when Mark Arnott stumbled across "zzGeneralFunctions.asp" as part of a maintenance project he was assigned, it was pretty clear why the file existed. Its first line contained the following comment:


Self-Documenting

by in CodeSOD on

Robert W and the rest of the peons in the COGS application group didn't have their own Architecture Team. Their break room wasn't stocked with an endless supply of snacks. In fact, they didn't even have the budget for quarterly "developer retreats". All they had was a CVS repository, a few servers, and a dedication to their client, the COGS group.

For years, everything ran smoothly: they delivered in full, on time, and had a very satisfied client. That is, until the elite developers from Central IT got wind of their rinky dink operation. After a week-long assessment, they determined that Robert’s team had a number of “serious trouble points”, the worst of which was JavaDoc compliance. Apparently, only 53.8% of their code was fully and properly documented.


Well, at least it compiles...

by in CodeSOD on

Working on a team that is uplifting a legacy application into a newer technology, Neil K. is responsible for ensuring that the new application is working the same as the one being replaced.


That Kind of Security

by in CodeSOD on

Alexandre Hetu was thrilled to not only be out of college, but to land a job at a small development company. He was even happier when he was given his first assignment: develop a shiny, brand-new application.

"I'm surprised they don't have any software to do this now," Alexandre told his boss after learning the business requirements, "or, were they using some vendor product?"


Spaced Out

by in CodeSOD on

"While going through some old code," John Preston writes, "I found this interesting set of global variables."

Private space1, space2, space3, space4, space5, _
        space6, space7, space8, space9, space10, _
        space100 As String

The Complicator's Email Address Parser

by in CodeSOD on

A builder sits you down at a table. "I want to show you something," he says, setting a rolled-up sheet of worn leather on the table in front of you. He reaches into his pocket, producing a single screw.

"I keep seeing these," he says, "and they're so hard to work with! I use my hammer to drive them in, but they don't work as well as nails. And once I finally get them in, the claw can't get under the head if I have to remove them." You start to feel embarrassed for the builder.


Foolproof Future-Proofing

by in CodeSOD on

"We had a coder for our project named Clyde," Robert B. writes, "who would have been much happier coding in C, but we had good reasons for choosing VB instead. To make up for the ease of coding in VB, Clyde would eschew the simple way of doing things. No calls to well-defined common routines for him; no, he would code deeply inscrutable functions to accomplish even the simplest tasks.

"Eventually, it came time to move the application to a new, web-based platform. We weren't porting the code – after a decade of Rapid Application Development, it was an unholy amalgamation of conflicting 'common' routines and wildly divergent programming styles. But we did have to document the functionality behind the existing system.


Rly, Rly, Rly Tru

by in CodeSOD on

A.C. found this in a project:

public override bool IsActive() {
  return true && true && true; 
}

A Common C Dilemma

by in CodeSOD on

How to prevent for-loops from boundary overrun?

Gordon's c/w came up w/ this cunning solution: