Steve D'Aprano wrote:
(1) I know there's a bug in a specific chunk of code, but I'm having trouble working out where. When everything else fails, if I perturb the code a bit (reorder lines, calculate things in a different order, rename variables, etc) it may change the nature of the bug enough for me to understand what's happening.
> Its an experiment, but not really "carefully designed". I think it's more carefully designed than you give it credit for. You still need to understand quite a lot about the program to know what changes are likely to yield useful information, and how to interpret the results.
Its more like "what happens if we hit this bit with a hammer?"
In biology it's called a "shotgun experiment". "If we blast this bit of DNA with radiation, what part of the organism does it mess up?"
(2) I hate off by one errors, and similar finicky errors that mean your code is *almost* right. I especially hate them when I'm not sure which direction I'm off by one. If you have unit tests that are failing, sometimes its quicker and easier to randomly perturb the specific piece of code until you get the right answer, rather than trying to analyse it.
With off-by-one errors it's still pretty specific -- start the loop at 1 instead of 0, etc. But in cases like that I prefer to rewrite the code so that it's obvious where it should start and finish.
The complexity of code increases faster than our ability to manage that complexity.
And then there's "If you write the code as cleverly as you can, you won't be smart enough to debug it!" -- Greg -- https://mail.python.org/mailman/listinfo/python-list