I’ve enough fixing crap like this and I hope these series will give you a sense of what bad code is. This is what I encounter EVERYDAY in my life right now and I’m getting very sick and tired of this. You’ve seen me lament about it on twitter, posted some code on Facebook. This time, I’m going to log this down as a blog post series. Here’s the first code snippet from my long list of other code snippets. Having fun with booleans.
[sourcecode language="csharp"]
bool x;
bool y;
// … some code to assign y
if (y == true)
{
x = true;
}
else
{
x = false;
}
[/sourcecode]
This is ACTUAL CODE. I’m NOT KIDDING YOU. This is what I see in production code. I didn’t leave out any additional code except those in comments.
[sourcecode language="csharp"]
bool isReady = false;
if(isReady)
{
// … do a bunch of stuff
}
else
{
// … do other bunch of stuff
}
[/sourcecode]
You want more? I almost flipped when I saw this code.
[sourcecode language="csharp"]
if(1 == 1)
{
// … do a bunch of stuff
}
else
{
// … do a bunch of other stuff
}
[/sourcecode]