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.

Jun 2008

Rigid XML Parsing

by in CodeSOD on

Sure, we've chronicled horrible methods of storing data in XML, but what about when you want to retrieve said data? If you're into .NET, you're probably thinking of something in the System.Xml namespace. If you're a Ruby developer, you're probably thinking of REXML. If you're using PHP, the XML Parser extension. If you're a COBOL programmer, then you're probably praying for death.

Well, if you consider yourself a senior-level XML developer, here's a new technique you can add to your repertoire, courtesy of Paul. Here's an example of a technique dubbed Case-Sensitive Replacement-Based Element Parsing, suitable for all* of your XML documents!


This Application Sucks

by in CodeSOD on

When Michelle M. started her new job, she feared the worst, but hoped for the best. She'd be maintaing an app that had been around since the 1980s and made an impressive tour of technologies — from Clipper to VB to VB.NET and finally to C#. So I guess she didn't so much fear the worst as expect the worst.

That faint little ray of hope she had that the code wouldn't be so bad was shattered when she met the senior developer. The first thing he said to her was "the application sucks." Michelle smiled slightly, unsure if he was kidding (he wasn't). "I mean it really sucks," he reiterated.


A Dubious Honor

by in CodeSOD on

"At my workplace, we have a wiki for the 'WLC' — the Worst Line Competition," Kirk writes. "We post lines of code that the lead developers have decided were good additions to the applications that we port. Here is one of the better ones:"

patno -= ((((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1)+1);

It Gets Worse Each Year

by in CodeSOD on

"A while back," Steven Victor wrote, "I was asked to look at an issue where numerical data 'kept getting more and more inaccurate' in newer versions of a software product."

"After some searching, I came across some code that converted an integer into a string representation of the value. It used the common "itoa" function, and since it was pretty run-of-the mill data meant to be interpreted by humans, the string was supposed to a base-ten representation.


wtflib.php

by in CodeSOD on

"While updating on some delightfully unorganized PHP code (no indentation at all, split over hundreds of randomly named files, many included dozens of times), I kept running across comparisons such as:

if (MatchField($login->Value("admin"), "==", "1")) {

More Randomer

by in CodeSOD on

John B. saw some strange code that prompted him to investigate.

Dim rNumber As Integer = 0
rNumber = RandomNumber(13, 1)
Select Case rNumber
Case 0
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 1
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 2
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 3
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 4
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 5
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 6
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 7
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 8
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 9
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 10
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case 11
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
Case 12
Me.hl_logo.ImageUrl = "~/sysimages/header.jpg"
Case Else
Me.hl_logo.ImageUrl = "~/sysimages/header2.jpg"
End Select