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.

25 Aug 2015

Foxy Checksum

by Remy Porter in CodeSOD on 2015-08-25

Pavel D inherited some… we’ll call it “software”… that helps run warehouse operations for a boiler/heating manufacturer. That software was a Visual FoxPro database.

Now, this application needs to read barcodes off of products in the warehouse. Since the laser-scanners can sometimes mis-read those barcodes, the database uses a custom check-sum algorithm.

57 Comments - Last Comment @ 2015-08-28
18 Aug 2015

At Least There's Tests

by Remy Porter in CodeSOD on 2015-08-18

Having automated tests for a project is a good thing, as a general rule. We can debate the broader merits of “TDD”, “ATDD”, “BDD”, “ATBDDSM”, how much test coverage is actually worth having, and if we should view our test approach as a series of metrics that must be met, instead of some guidelines that will help improve our development process.

Our first exhibit today is from Paul. It’s a JUnit test, that, well, maybe misses the point of writing unit tests:

39 Comments - Last Comment @ 2015-08-19
11 Aug 2015

Count On It

by Jane Bailey in CodeSOD on 2015-08-11

“Duct-tape

If there's one thing more exhausting and ridiculously over-complicated than moving house, it's moving legacy apps. Something as simple as a migration to another, identically configured (in theory) server can cause unexplained breakages and weird glitches in bits of the code no current staff member has ever touched.

72 Comments - Last Comment @ 2015-08-24
06 Aug 2015

Listicle

by Remy Porter in CodeSOD on 2015-08-06

The Top 10 Ways to See if an Item Is in a List, Only 90s Kids Will Get this

Pardon the clickbait headline. We’re only going to look at one method to tell if an item is in a list. A bad one.

Andrew M. inherited some software that tracks metrics. There are three general categories of metrics- “MS”, “FN”, and “CM”. Each of these categories contains a number of specific metrics, each assigned its own ID.

212 Comments - Last Comment @ 2015-08-25
03 Aug 2015

Save Yourselves!

by Dan J. in CodeSOD on 2015-08-03

Scott K was cleaning up a configuration utility used by his team when he dredged up this sanity-threatening artifact:

void Save(string path)
{  
    XmlTextWriter write = null;  
    try
    {  
        write = new XmlTextWriter(path, null);
    }  
    catch (IOException)
    {  
        write.WriteEndDocument();  
        write.Close();  
        try
        {
            write = new XmlTextWriter(path, null);
        }  
        catch (IOException)
        {
            return;
        }
    }  
 // Write stuff to the file
}  

19 Comments - Last Comment @ 2015-08-03