Learning New Things Everyday

It’s humbling to be a veteran programmer and make a very drastic mistake. Today I made a startling discovery that two libraries I wrote contain two C functions with the same name. They do almost exactly the same thing too. Their names were RemoveClient(). The fact that they have the same name is not so surprising, what is surprising is that one of my programs which makes use of these two libraries had a segmentation fault today. I was dumbfounded at first as a backtrace of the stack calls looked normal yet one of the variables passed to RemoveClient() was NULL. That made no sense as the variable was declared on the stack and should always be valid for this code to even run.

It wasn’t until I looked a bit closer at the backtrace when I realized the unbelievable. The code was calling the RemoveClient() from the other library instead of the proper one declared within. I’m admitting this major mistake because I think it’s important for people to realize that there can always be flaws in your logic. Programming is almost completely a task in logic, which I should unquestionably be an expert at. Yet I made a very simple mistake of overlooking declaring these functions as static.

After realizing my mistake, I instantly thought: “how the heck have I avoided making this mistake in all my years of programming?” Well that was relatively easy to answer. I have always made sure my functions and variables are very descriptive and uniquely named. This time however I was under the gun to get this code completed and when rushed I’ve been known to simply copy and paste. Which by the way, I have made more errors in coding when copying and pasting my own code. It has to be the worst thing a programmer can ever do.

Anyway, the point I hope everyone will take from my experience, is try hard to be the best at what you do, but don’t let being the best blind you from your potential to make mistakes.

Tags: ,

Leave a Reply