I’m having such a great time dealing with lazy code. Check out these gems I’ve found just today …

var periodError 
    = string.Format(
        "The Survey Return does not contain a valid Reporting Period");

Why format something that with no parameters? I changed the code to this:

var periodError 
    = "The Survey Return does not contain a valid Reporting Period";

Here’s another good one:

var periodError
    = string.Format(
        "Specified period {0} does not match the expected period {1}.",
        surveyReportingPeriod.ToShortDateString(),
        aReportingPeriod.ToShortDateString());

Let’s completely avoid the format specifiers and convert everything to strings manually. I changed it to this:

var periodError
    = string.Format(
        "Specified period {0:d} does not match the expected period {1:d}.",
        surveyReportingPeriod,
        aReportingPeriod);

What I’m finding really frustrating is that I know the developer who wrote this code, and he’s a smart guy who writes good code most of the time.

Upon reflection, I’d suggest that this code is less important for the actual errors, and more as a reminder that we all can make those errors, even (or especially) those of us who think we’re pretty good at what we do.

Comments

blog comments powered by Disqus
Next Post
Specialist Classes  22 May 2010
Prior Post
Simplicity  19 May 2010
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
May 2010
2010