Purposefully debugging without using a debugger?

后端 未结 20 1858
春和景丽
春和景丽 2021-02-01 08:49

In chapter 5 of \"The Practice of Programming\" Brian Kernighan and Rob Pike write:

As a personal choice, we tend not to use debuggers beyond getting a st

20条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 09:27

    I think Kernighan was trying to make a point about mindful analysis. Don't dive in amonst the trees without understanding the forest. That said, there are other reasons to prefer different tools than the debugger, as aides to your mind.

    My favorite (if that's the right word) example, is memory bugs. In a language like C or C++, misuse of the memory system (double deletes, accessing objects through dead pointers, running off the end of an array) can corrupt the program in such a way that the problem does not manifest itself anywhere near the original cause.

    The appropriate approach in these languages is to use practices which eliminate those errors, but failing that, tools are also valuable. When my experience with similar bugs leads me to suspect "this feels like a memory error", I reach for valgrind, before I ever think "debugger".

    Now we can begin the argument that automatic memory tools and bounds-checking libraries are debuggers! ;^)~

提交回复
热议问题