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.

Jan 2010

Break Out

by in CodeSOD on

“I’m continually amazed by the unique and clever solutions developed by my colleagues,” Mark writes. “And I should say, I don’t mean ‘amazed’ in a good, innovative-idea-to-save-company-money sort of way. It’s more a wow, that’s more wrong than I could have ever imagined sort of way.”

“Take, for example, this snippet of code that I found recently.”


Meaningless Progression

by in CodeSOD on

"One of our desktop applications has a progress bar in it," Bryce N. writes, "and as I was working more and more with the code, I noticed that the progress bar would progress to a seemingly random part in the bar, but never past the halfway mark. This would probably be ignored, if it weren't for the fact that I noticed that my breakpoints would only be hit when the bar reached the 'random' mark."

"While I was trying to discover why, I found this in the code:"


Piecemeal SQL

by in CodeSOD on

I can see it now.  Everybody will say how the following bit of Java code that Shawn C. has sent in isn't actually a WTF and is, in fact, quite brilliant.

To a point, I agree - the code works, and leaves the door open for accomodating changes to the structure of the SQL queries themselves. Especially if, some day, in a far flung future when, from out of space, a runaway planet comes hurtling between the Earth and the Moon, unleashing cosmic destruction casting civilization into ruin, forcing mankind to re-invent the standard keywords used to retrieve information from databases.


Helpful SQL Helpers

by in CodeSOD on

"I recently had the chance to work on one of our projects that has been in development for longer than I have been employed here," writes Phillip, "back when the project was first started, a large part of it was outsourced overseas because, well, that was all the rage back then."

"I was assigned a few relatively simple tasks, which afforded me the opportunity to poke around the code for a bit. One of the first things I found was this, right at the top of SqlHelper.cs."


Insert Comma?

by in CodeSOD on

"While browsing the code base of a recently inherited project," Joey L writes, "I found this curious method."

    private String insertComma(String src){

           StringBuffer result = new StringBuffer();
           try {
                           char d = '"';
                           result.append(d);
                           result.append(src);
                           result.append(d);
                  
            } catch (RuntimeException e) {
                logger.error(e);
            }
            return result.toString();
         
    }

The Integer Cache

by in CodeSOD on

A few months ago, Hugh accepted a contract assignment to work on a Java project and, ever since starting, his day-to-day has felt a bit like the old game of Zork: a maze of twisty passages, all alike. So far as he can tell, a large part of the system was created by a chimpanzee (possibly orangutan) that received a treat whenever it pressed a giant button marked "Copy and Paste". One of the class files that Hugh has spent a bit of time working on has over 10,000 lines of code and at least one method that's over 2,500 lines long.

As Hugh navigated through the numerous methods like processEntry1, processEntry2, etc., he noticed an interesting pattern start to emerge.