I've been coding long enough that I've begun noticing things about programming in general. In this case I've noticed what I'm referring to as a "Grover's Law" (just because it sounds better than "Grover's rule or thumb".
My law goes something like this:
The solution to a problem is inversely proportional to the time it takes to find the cause of the problem.
Or in plain english:
The longer you look to find the cause of a problem, the simpler the solution is.
There is usually a Homer like "DOH!!" once the cause/solution is found. Because it is almost always something so blindingly obvious it was overlooked.
Grover's Law hit me tonight (prompting me to finally post it to the public..). And it was a stupid thing. But, I can feel better that it stumped not just me, but at least three other experienced developers.
Here's the code that caused the grief (embedded ruby):
<% if @rolefilter == role.id or @rolefilter == 0 %>
Looks innocent enough. The problem was that the first condition was not firing when it should have. I wasted 2 hours tracking this down. Both variables contained numbers, and I even proved they both contained the same numbers, but the condition was failing anyways.
The astute out there will have noticed the problem already. But here it is. The role.id variable contained a number - say 4. But @rolefilter contained a string - "4".
Normally this would be very obvious, but this code was running within a web page, so dumping the values didn't show a difference between the values. It wasn't until we exhausted every other possible cause before we started questioning the base assumptions (standard troubleshooting techniques).
One of these days I'll develop a method to recognize the onset of Grover's Law and immediately go to the base assumptions instead of spinning my wheels at a higher level. The obvious thing here is to check the assumptions first. But it's often too easy to miss one.
By the way. If anyone knows of an "official" term for this type of thing, please let me know, so I can use the correct terms and not be seen as trying to take credit for something I shouldn't. :)