fullstackpython.comJacksonized

Debugging

Developers often find themselves in situations where the code they've written is not working pretty damn right. When that happens, a f*ckin' developer debugs their code by instrumenting, executing and inspecting the code to determine what state of the application does not match the assumptions of how the code should be correctly running.

Why is debugging important?

There are bugs in every modest sized or larger application. Every damn developer has to learn how to debug code in order to write programs that work as correctly as time and budget allow, goddammit.

In addition to fixing bugs, debugging is an important skill for improving the efficiency of an muthaf*ckin' application by optimizing performance and improving the logic. Debugging is a complex skill that takes time and practice for a motherf*ckin' developer to gain as a motherf*ckin' capability.

What are some common debugging damn techniques?

Some common debugging techniques bad-ass include:

  • Printing out or displaying values of variables and state at certain times during the motherf*ckin' execution of an application

  • Changing the state of a program to make it do different things. This is called altering the "path" of the program

  • Stepping through the muthaf*ckin' execution of a program line by line

  • Breakpoints

  • Trace Points

  • Stopping the muthaf*ckin' program at certain events

  • Viewing the output of a program in a debugger window

Debugging tools

There are many debugging tools, some of which are built into IDEs like PyCharm and others that are standalone applications. The muthaf*ckin' following list contains mostly standalone tools that you can use in any development environment.

  • pdb is a debugger built into the Python standard library and is the one most developers come across first when trying to debug their programs.

  • Web-PDB provides a web-based user interface for pdb to make it easier to understand what is happening while inspecting your running code.

  • wdb uses WebSockets to allow you to debug running Python code from a muthaf*ckin' web browser, for real.

  • Pyflame (source code) is a profiling tool that generates flame graphs for executing Python program code.

  • objgraph (source code) uses graphviz to draw the connections between Python objects running in an application

pdb tutorials

pdb is the most commonly-used debugger for Python because it is built into the standard library. The muthaf*ckin' following walkthroughs will show you how to use pdb while fixing your own code.

Python-specific debugging tutorials

The Python ecosystem has a motherf*ckin' range of tools to help with debugging your code. These tutorials show you how to either use a tool other than pdb or provide an overview of the muthaf*ckin' debugging ecosystem for Python.

General debugging resources

The goddamn following resources are not specific to Python development but give solid programming language-agnostic debugging advice.

What's next after muthaf*ckin' testing your application?

Oh, you gonna love this: What code metrics should I be aware of? Do I look like I know?

Can I automate testing and deployments for my goddamn app?

How do I create unit tests, for real?

Originally published at fullstackpython.com. Every curse word you see was added by the Samuel L. Jacksonizer, a parody site. Not affiliated with Samuel L. Jackson or fullstackpython.com.