Editorial Note: I originally wrote this post for the SubMain blog. You can check out the original here, at their site. While you’re there, take a look at CodeIt.Right to help you automate elements of your code reviews.
“You never concatenate strings. Instead, always use a StringBuilder.”
I feel pretty confident that any C# developer that has ever worked in a group has heard this admonition at least once. This represents one of those bits of developer wisdom that the world expects you to just memorize. Over the course of your career, these add up. And once they do, grizzled veterans engage in a sort of comparative jousting for rank. The internet encourages them and eggs them on.
“How can you call yourself a senior C# developer and not know how to serialize objects to XML?!”
With two evenly matched veterans swinging language swords at one another, this volley may continue for a while. Eventually, though, one falters and pecking order is established.
Static Analyzers to the Rescue
I must confess. I tend to do horribly at this sort of thing. Despite having relatively good memory retention ability in theory, I have a critical Achilles Heel in this regard. Specifically, I can only retain information that interests me. And building up a massive arsenal of programming language “how-could-yous” for dueling purposes just doesn’t interest me. It doesn’t solve any problem that I have.
And, really, why should it? Early in my career, I figured out the joy of static analyzers in pretty short order. Just as the ubiquity of search engines means I don’t need to memorize algorithms, the presence of static analyzers saves me from cognitively carrying around giant checklists of programming sins to avoid. I rejoiced in this discovery. Suddenly, I could solve interesting problems and trust the equivalent of programmer spell check to take care of the boring stuff.
Oh, don’t get me wrong. After the analyzers slapped me, I internalized the lessons. But I never bothered to go out of my way to do so. I learned only in response to an actual, immediate problem. “I don’t like seeing warnings, so let me figure out the issue and subsequently avoid it.”