Code I Found
- June 15, 2010 4:24 PM
- General
- Comments (4)
Its time for a new category here on my blog... I've been working through a good bit of older code at work and trying to update it to something like modern developer standards. Part of the fun of this has been finding weird, pointless language constructs. Check out this C# example:
EnableEditButtons(true);
else
EnableEditButtons(false);
Neat! This developer was able to use 4 lines of code to do one line of code:
Do you have any good examples of code that just shouldn't have been?
Update!
The EnableEditButton() function from the last example is worth a look too...
{
if (Value == false)
{
buttonAdd.Disabled = true;
buttonDelete.Disabled = true;
}
else
{
buttonAdd.Disabled = false;
buttonDelete.Disabled = false;
}
}
Could be wrapped up as:
{
buttonAdd.Disabled = buttonDelete.Disabled = !Value;
}
Comments
Also, if someday you needed to perform additional tasks depending on the value passed to enableEditButtons(), you'd have to revert to the original if/then statement anyways.
It's tempting to fix every little thing your predecessor did wrong, but it sure wastes a lot of time. I'm not trying to promote "bad code" here, but clients honestly don't care what the code looks like, as long as it works.
I try to follow these wise words when coding:
"If it ain't broke, don't fix it" and "Keep It Simple, Stupid"
Now the question becomes: what will you do with all the time I've just saved you?
In the end I know that these changes don't save time, just as you say. Things to think about. Thanks!
You have find out what i am also realized while looking code, anyway nice work...