Purposefully debugging without using a debugger?

后端 未结 20 1798
春和景丽
春和景丽 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:25

    The reason to use debugger as a last resort?

    Because ,usually, I can find the bug much faster by using other techniques than using a debugger.

    0 讨论(0)
  • 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! ;^)~

    0 讨论(0)
  • 2021-02-01 09:27

    Print statements that get dumped to a file can be operated on textually. grep, sort, sed, and awk can help for complex debugging issues. Also one could write a small program to parse the dumped text if necessary.

    0 讨论(0)
  • 2021-02-01 09:28

    I use debugger only as last possible solution, because with debugger I often have to trace tons of code which has nothing to do with my problem. So I prefer to use my intuition and place some prints at places where could be problem. With this I solve 99.9% bugs very quickly. No 3 day debugging here!

    0 讨论(0)
  • 2021-02-01 09:29

    Not using the debugger to F10/F11 through your code can make you a better developer.

    During my 1st job I had done a lot of programming in Linux where Visual Studio debugger was not available. Because debugging was hard I've learnt how to analyse my code and really understand how it works. And I became a better developer because of that.

    Nowadays I do use the debugger only after I've gone over the code and searched for the "usual suspects" and if I do not understand how my code works without debugging it then I refactor it.

    0 讨论(0)
  • 2021-02-01 09:31

    Our software runs on Linux/Solaris/HPUX/AIX/FreeBSD/MacOS, and it seems very hard to get debuggers for some of those platforms, and much easier to just add some extra tracing code.

    0 讨论(0)
提交回复
热议问题