Thoughts from the office by Ed Ball
Wednesday, October 22, 2003

A coworker of mine found a bug in my code that was basically a result of a typo -- brain thinks one thing, fingers type something else -- and it got me to wondering if a really good compiler could have warned me about it. The offending statement:

if (nSelectedIndex == 0 && strColor == "other" && strColor != "")

Wouldn't it be cool if a compiler could notice that there's probably a bug here? The third comparison is pointless, since if the second comparison is true, the third comparison will always be true, and if the second comparison is false, the third comparison won't even be evaluated.

10/22/2003 9:53:27 AM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Code#
Search
Archive
Links
Categories
Administration
Blogroll