Wednesday, September 23, 2009

Why small mistakes are disastrous?

I made a stupid mistake. very stupid one!
if(!IsOK())
OkDoIt();
else
NoWait();
Do you see the problem?
Yes, only one character ruined the whole process.

It should be like this:
if(IsOK())  // if(!IsOK())
OkDoIt();
else
NoWait();
If the function containing this problem is rarely called, it's a time bomb inside a briefcase. Even after you recognize something is wrong, it's very hard to find this kind of mistakes because it's such a small one like off-by-one error. almost invisible. That's why small mistakes can be much more disastrous than big ones which are obviously more visible.

Since code like the above is usually written very quickly and unconsciously without thinking, if you don't have right habits, you will make a mistake. It brings me the idea I loved but, apparently, forgot.
Good programmers have good programming habits.
I will never use ! in if statement. ever.

One more thing to remember.
Test every changes you made.Every single line.
Of course, I tested my changes before I checked in it. However, there were many changes and I just quickly checked a normal flow without checking all the changes I made. I was focusing on bigger and more complicated changes. I should have kept my changes small and checked in them more frequently.

Anyway, it's absolutely my fault and I will never forget it.
I really don't think anything I do is a mistake. It could be if I didn't learn from it.
- Fiona Apple

Thursday, September 3, 2009

Did you know you can change wingdi.h ?

I was having a weird problem with compiling src files for a few days.

I couldn't remember when it started but the compiler kept saying it could not find "ERROR" identifier. "ERROR" is supposed to be in wingdi.h like this.

#define ERROR 0

So I checked my wingdi.h file and it was like it.

#define LOG 0

It didn't take too much time to realize that wingdi.h was modified recently and all the other header files in the same folder had not been changed at all ever since the visual studio was installed.

I thought it was because I installed some other SDK or programs and I tried to figure out what made this situation. I had never imagined that I changed it. But, yes, I DID IT. OOPS!

I did "replace all" ERROR with LOG for my own project and wingdi.h was open at that moment. Visual Studio modified it and did not say anything when I saved and compiled it. There was no single error because I did not use ERROR in that project.

First of all, wingdi.h is NOT read-only so if you accidentally modify and save it, you won't see any warnning dialogs. Second, Visual Studio applies "replace all" for all opened files which are not in your solution even though you choose "Entire solution". Like the below picture.


So be careful otherwise you could waste hours even days like someone. =+=