I’ve got a few boneheaded mistakes I make over and over again, as I’m sure every programmer does. The one I’ve been making lately is with CString’s CompareNoCase method, thinking it returns TRUE/FALSE when it actually returns -1/0/1 (like the CRT strcmp function). Basically I wrote this:
instead of writing:
if (str.CompareNoCase("blarg") == 0)
Obviously it produced the exact opposite result. I just did it again yesterday and spent the better part of an hour tracing through code, adding log messages, pulling my hair out trying to figure out why a bit of code wasn’t working, before I finally realized the mistake.
I think it’s bad programming to have written the CompareNoCase method this way in the first place. It should be a BOOL method, or at least there should be another BOOL method available. I’ve used CompareNoCase a lot but I can’t recall ever using it for a relative comparison.