Purposefully debugging without using a debugger?

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

    I use a debugger when :

    • I'm almost certain it is something stupid that I missed somewhere (variable not initialized, test conditions inverted or some other smack in the forehead god i'm stupid kinna stuff)
    • The test still fails and I just cannot figure out why
    • It is hard to track logs because of frequent context jumps (listeners, callbacks etc) and the loggers are not contextualized (named after the class and not after the context)

    In all it is a balance between speed and accuracy. However from experience if I end up spending a lot of time around a piece of code there is a good chance I will have to come back to it, so I add logs and I add tests so I do not have to come back to it, or it I do all the work I have done to understand the code remains and I can build on top.

    One reason I do not like debuggers is that all the work I do figuring out how it works is wasted once the debugger is off. If I spend the time learning about a piece of code I want this knowledge to be available the next time I (or someone else) get to it. Adding trace code is a very good way to have "Dynamic comments" that is always there and can be summoned anytime.

    At large... pretty much anything that is removed before shipping to the customer I shy away from. If I put a safety net around my system there is no reason my customer cannot benefit from it while using it as I did while programming it. This is especially true if I am the one that has to support it afterward... I hate supporting so I want to make it as painless as humanly possible.

提交回复
热议问题