Don’t Blindly Follow a Tool’s Suggestion

Uncategorized

Resharper likes this:

 foreach (IRoutableRequest item in this)
            {
                if (item.Id !=
                    request.Id)
                {
                    continue;
                }
 
                Insert(IndexOf(item) + 1,
                    request);
                Remove(item);
                break;
            }

 Instead of this: 

foreach (IRoutableRequest item in this)
            {
                if (item.Id ==
                    request.Id)
                {
                    Insert(IndexOf(item) + 1,
                        request);
                    Remove(item);
                    break;
                }
            }

Doing a negative comparison (not equal) and continuing in the loop is HUGELY counterintuitive. Counterintuitive is pretty much the same thing as not maintainable. We strive for maintainable above all else, generally. So, while Resharper helps us tremendously with this goal, sometimes, it tells us just the opposite. Its just a tool, and an automated one. Its not perfect. Remember to use your judgment. If we could write code without any judgment, then they wouldn’t need us, and we be out of jobs…

Advertisements