Side effects matter

One of my cow-orkers used his new fancy GUI IDE that showed him that a variable wasn’t being used in my code, so he commented it out. Only one problem: the variable was one of a list of variables being retrieved from a SQL select statement, and like is common with these things, I was retrieving them with:


int a = rs.getInt(p++);
int b = rs.getInt(p++);
String c = rs.getString(p++);

Notice the problem there? If you comment out one of the getInts without removing the field from the select statement, you also lose the “p++”, so everything after it gets the wrong field stored. Which causes a pretty nasty little bug.

Thanks, guy. That’s a few hours of my life I’ll never get back.