Tuesday, September 12, 2006

For some reason, it really bothers me when I see this pattern in code (using no particular language):

someVar = false;
if (someCondition) {
   someVar = true;
}

This can, of course, simply be specified as:

someVar = someCondition;

Now, I understand that as code is refactored, this pattern can appear due to simplifications...but still...come on. It's even worse when someVar is used only as the condition of another if block.

UPDATE: This seems to occur most often in code whose ownership has changed hands several times. New owners seem to fall into either trying to edit the code while maintaining the structure as closely as possible, or by heavily refactoring. Many times, the former choice is made, especially if the original owner is still around somewhere. Usually my first instinct when I inherit code is to massively refactor. I'll post a more in-depth view on this later.