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.

Aug 2007

Patiently Waiting Forever

by in CodeSOD on

Today's snippet comes from an issue that Brian discovered in the production code of a large telecomunication company's call center software. It attempts to solve a fairly simple problem: get the handle to a specified window and, if it can't be found, try again for MAX_SECONDS. However, there was a bit of an issue with the default wait time...

 


Overflowing Style Sheets

by in CodeSOD on

When Lex submitted a large snippet of code from an older ASP/VBScript application that he had inherited, I was considering extracting the following single line and publishing it as a Representative Line...

set rsCSS = db1.execute("select * from tblCSSClasses")


When the Query String Is Just Not Enough

by in CodeSOD on

As Stephen A.'s client was walking him through their ASP.NET site, Stephen noticed a rather odd URL scheme. Instead of using the standard Query String -- i.e., http://their.site/Products/?ID=2 -- theirs used some form of URL-rewriting utilizing the "@" symbol in the request name: http://their.site/Products/@ID=2.aspx. Not being an expert on Search Engine Optimization, Stephan had just assumed it had something to do with that.

A few weeks later, when Stephan finally had a chance to take a look at the code, he noticed something rather different...


Multi-threaded PHP

by in CodeSOD on

Despite what our teachers may have said, there is such a thing as a stupid question. And generally, newbies are the ones asking ‘em. I know I sure did (thankfully, under a pseudonym). But unlike the mean-old folks who would often answer my questions (“RTFM, idiot!”), I don’t believe in picking on those trying to learn. In fact, today, it’s time to pick on someone trying to teach…

Gonzalo Larralde pointed me to discussion on a coding messageboard where a poster asked a fairly simple, naïve question: “How do I create a multithreaded application using PHP. i want to write scripts that run parallelly.” As I’ve discussed before (see Pounding A Nail: Old Shoe or Glass Bottle?), my response would have been an explanation of what’s fundamentally wrong with such a question. Another poster, however, had a different answer…


Globally Local

by in CodeSOD on

Everyone knows that global variables are a Bad Thing. It's not too clear why they're bad, but it probably has something to do with speed. Think about it. You never know where a Global could be (it could be across the Globe, after all!). But a Local variable -- it's always right there, nearby.

Serge's colleague discovered a way to gain all the benefits of global variables without hampering performance too much ...


Eval This!

by in CodeSOD on

While reviewing some old JavaScript code in his company's core application, Dan Howard came across this pain.

For some reason, the "developer" decided that he has to Javascript's Eval() for each line of code. Some in a try/catch... others without...


My Kind of copyFile

by in CodeSOD on

After running this site for a little more than three years, it’s rare that I’ll come across a snippet of code that leaves me speechless. Today’s snippet comes from a large Java application that Byron recently started working on and is … well, I’ll just let the code do the talking…

 


Coded to the Letter

by in CodeSOD on

Today’s first snippet comes from some work that was submitted to Yndy from a new coder for his company’s code review. The second snippet is the revision to that code.

Yndy’s company’s coding standards are pretty straightforward. One states “variable names shall differ by more than one character.” It’s pretty reasonable: who wants to accidentally use “day” instead of “days” when both are declared in scope? Another is just as reasonable: inline comments should be added at the point of variable declaration to make the code more understandable. Apparently, neither rule made sense to Yndy’s coder…