Cykod

Know when to debug, know when to flail

by Pascal Rettig posted Mar 16, 2010

These definitions are definitely not universal, but here are my definitions of two different ways of fixing programming problems:

Debug (v) - To trace a program's path of execution to a known state and then forward to find a divergence from expected behavior.
Flail (v) - To keep trying different sh*t until something works.

Both Debugging and Flailing can use the same tools. You can debug with print statements and you can flail with Visual Studio's line-debugger. The difference is more a question of how you approach the problem rather than the tools you use to do it.

A classic example of flailing is getting an off-by-one error in a loop and to just keep changing your conditions until it seems like the solution is right. It's a lot easier to just make a couple of code changes and let the computer do the thinking than to stop and actually understand exactly what's going on.

In general debugging is involves a much larger context switch as you have to wrap your mind around a much larger piece of code and step back and understand the bigger picture of what you are doing. If you a fixing a smaller self-contained problem you just introduced, a full-stop debugging effort may not be worth the effort. That said, for the other 96%** of the problems you come across, Flailing isn't the answer.

In particular, If you are fixing a problem that does not relate to code you wrote recently, going the flailing route will invariably introduce bugs that weren't there before, as you will miss boundary conditions or get something to work for only a subset of you possible inputs (barring 100% bullet-proof test coverage)

The other major problem with flailing (and remnants of this are apparent in a lot of CSS file that I look at), is that even if you solve the problem, you end up with additional cruft that may not have been needed to reach a solution and you'll never know what it was that you did exactly to make things work.

If you are really up a creek as to where the problem lies and know you are going to have to try a multitude of different attacks, one solution is to try one thing and reset your VCS back to a known state before you go and try something else. That way you won't end up with attempted fix piled on top of attempted fix.

 

** - Made up Number