Thursday, March 19, 2009

Probably something stupid...

I kept a mantra for my years in C and C++, and frankly I lost it when I was working in Python (probably a strong recommendation for the language). It is a useful and deeply wise saying, though.

You will someday find yourself in a little bit of confusion. A minute ago, the code was fine. You just made a very small change hoping for a very specific effect. Instead, the results you get are completely bizarre. Something deeply strange is happening, and it's not the effect you were looking for at all. The error messages are bewildering and seem totally unconnected with your change (especially if you're in C++ or Java).

Take a deep breath. Smile for therapeutic value. Close your eyes for a second, and look at your partner. Repeat the mantra:

It's probably something silly and syntactic.

This came about today, because we forgot to put a "virtual" on a method we were mocking. We've done this many many dozens of times in the past few weeks, but it's a manual step that you have to perform or your mock fails and the resultant error may be deeper in the code than you expected. You could make a list of all these things, but eventually you will find yourself digging in deeper than you need to.

Don't. Remember that it's probably something silly and syntactic.

I've had this over badly formatted templates, silly errors involving single v. double operator spellings (+ v. ++, = v. ==, * v **) and any number of silly typing accidents. Hey, and expert is just the guy who knows what all the mistakes look like.

Before you start scratching your head, chasing your tail, or pulling your hair out (as I must have) you should probably just recite the mantra and look at the change once again.

Oh, and because silly syntactic mistakes happen, don't let yourself have seven places or a half-dozen changes that might be wrong. You want to have one reason to be wrong, and you want to know right where it is.

If your partner did not catch the error, and the result is not what you thought you would get, relax. It's probably something silly and syntactic.