Chris Angelico wrote:
On Sat, Sep 30, 2017 at 2:42 AM, Steve D'Aprano
<steve+pyt...@pearwood.info> wrote:
Oh, and I'd like to make a (moderate) defense of a kind of "bug fixing by random
perturbation". Obviously making unrelated, arbitrary changes to code is bad.
But making non-arbitrary but not fully understood changes to relevant code
sections can be useful in (at least) two scenarios.

(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.

That's not *random* or *arbitrary* changes, but they are changes not directed at
any specific outcome other than "make the code a bit different, and see if the
error changes". I'd like to say it is the debugging technique of last resort,
except its perhaps not quite as *last* resort as I'd like, especially in code
I'm not familiar with.

Its an experiment, but not really "carefully designed".

I'll write for the possible benefit of any beginners who may be reading. I guess by definition, if one still has a "bug" it's because one doesn't quite understand what the code is doing. And I would say you should lose your license if you "fix something", and don't understand why it works (within reason of course--some mystery's of library functions should probably remain so forever). So ADT (Any Damn Thing--I just made that up that acronym) you can do to understand your code better is fair game! : ) In fact, in my experience, the sooner you start getting a little bit angry, the sooner you'll get to the heart of matter. Usually, what looks like a long route, isn't, in the end. Don't be afraid to write *really descriptive* output statements, and do so even though you "don't need to". Besides for making you more productive, it will help soothe you : ) Beginners almost never need to... I think that getting out of the beginner phase requires developing a certain amount of humility. Just wait 5 or 10 years, any look back, and see if what I've written isn't more true than false.

The only part I am unsure of is whether you are supposed to get a little big angry or not (YMMV). I find 2 cups of coffee about right. That is, 2 before and 2 after lunch. Of course, that does not include "meetings".
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to