Best Practices for Debugging?

There’s some good discussion here about when and when not to use debugging

So, when do I not need a debugger?

I am not the smartest coder, nor the most experienced, but still, sometimes I do not need to use the debugger. That is when:

The code is mine or well-written AND
It is written in a readable language AND
The overall project is small.
When do I rely on a debugger heavily?

Short Answer: often.
When an application crashes. Particularly when it is deployed. Having VS2010 installed on that computer can make a difference between "Unknown Error" and FileNotFoundException.
When a 3rd party library crashes or misbehaves.
When the code is poorly written. Particularly if the same file was touched by 10 different people in the last 10 years, 7 of which are no longer with the company.
When the project is large
When the code is rather monolithic.
When there are several tiers (GUI, SQL, BL) involved.

But it’s a little outdated (2011).

Personally I feel:

Don’t use a debugger

  • For a technically simple website with very limited features
  • Prototype
  • Codebase you work in every day

Use a Debugger

  • Large codebase, including a microservices codebase
  • Mainly for backend django code, JS code in my exp. is serviceable with console.log(), css is usually the pain.
  • An unexpected crash

I was wondering what the Django communities’ thought’s were?

Not specific to Django, but:

A debugger is just another tool in the toolbelt. It’s not magic and it’s not a silver bullet.

Personally, I think it’s more important to know how to use one, and to understand the information it can provide to you when trying to diagnose problems.

You can then make an informed decision on a case-by-case basis as to whether it’s going to help you or not.

It’s a whole lot better to be in the position of “I don’t need to use a debugger here, I understand what’s happening in the code” than to have to say “I don’t understand what’s happening in this code and I can’t figure out how to find out where things are going wrong.”

Learning how to effectively use all the tools available to you is part of one’s personal development as a programmer. This transcends all other considerations of language, framework, operating system, etc.

Could you give me an example of how you would apply this in practice?

Apply what in practice? Using a debugger?

Not using a debugger but some detail in the decision making process in whether or not you’d need one.

eg. For me, I’d use one if I was looking at a crash and the logs didn’t do a good job describing the executed steps

I guess I would say I don’t start with “I’ll use a debugger”. I gather whatever information is available to me and see if I can find the cause of the problem.

I either have enough information or I don’t.

If I don’t, then I figure out what information I need and decide how I’m going to get it. It may or may not be by using a debugger. There isn’t a hard & fast rule, it’s purely a judgement call.

1 Like

Thanks for the info, I think intuitively I think in similar patterns. What kind of coding work do you do? Full-time job, contracting, side project work, etc. and what kind of systems do you contribute code to?

While I understand the curiosity behind your questions, I don’t believe this is necessarily the right forum for discussing such topics. It’s getting out of the realm of being a Django-related topic, and I really don’t want to get the moderators upset with me. I’m open to continuing this conversation in other channels.

I’ll use a debugger if it’s easier to do than throwing in a print/console.log statement. I haven’t found an easy way to integrate PyCharm, Poetry and our environment variables yet (I’m due for another attempt), so I tend to use a lot of print and logger statements when I’m dealing with the backend of my day to day application. However, on the frontend, I’m much more likely to use a breakpoint on the frontend and div into the code there. Browsers make it so easy these days.

As Ken mentioned, it’s a tool. A particularly useful tool when your mental model of the code doesn’t match the code which you seem to agree with:

1 Like

I basically just rely on loggers for backend debugging too, that and googling around.

I hear you, thanks for the conversation so far.

How can I get in touch?

Direct message in Twitter is probably the easiest, “most private” channel to continue this.

1 Like