Use the Debugger
As I continue my journey as a developer, I start to realize that what I do on a daily right now may not translate to the real world. What…
Use the Debugger
As I continue my journey as a developer, I start to realize that what I do on a daily right now may not translate to the real world. What will my challenges be when I become employed? Will my tasks be test driven or will I have to find a way to run and test my code without breaking the project?
In a perfect world, things would work the same as what I learn now but unfortunately it doesn’t. Luckily, most, if not all modern technology, have built-in tools to help debug what code you write. Debugging your code means to identify coding errors at various stages of the operating system or application development. VS Code, a source-code editor, has great debugging support.
From the visualstudio webpage, “VS Code has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, or any other language that gets transpiled to JavaScript.” You can also download extensions for other languages like Python, Ruby, C++, etc, however, with my time learning Python, I did not.
I have been learning Python these last couple of weeks and I cannot express how much debugging has helped. At first, I rarely used it because all of our deliverables were test-driven but as we started to move along, I realized that was no longer apparent. With Python, you can use pdb, the Python Debugger, or ipdb, the IPython-enabled Python Debugger.
- pdb is a built-in interactive debug tool of the Python library. It allows the developer to enter a shell at breakpoints, set by them, to inspect and test the functionality of the code.
- ipdb, per skillshats, “is a third-party interactive debugger that extends the basic functionality of the pdb debugger with IPython support. This means that ipdb has all the features of pdb with added benefits such as tab completion, color support, magic functions, and much more.”.
I used the latter.
Assuming you are familiar with Python and have already installed into your local environment, follow below to install ipdb and get a brief explanation on how to use it. If not, make sure to look up installing pyenv, python and pipenv first.
To start, in your terminal, run the command in your local environment to install ipdb.
pip install ipdb
Once installed, open your python application and run these commands to install the necessary packages from your Pipfile.
pipenv install
pipenv shell
Adding this statement to your app, either at the top of your app/module or where you want your breakpoint to be, will allow you to step into your debugger at that specific point of your code.
import ipdb // <- this is the statement //
def testing_the_debugger():
before_the debugger = "You will see this!"
print(before_the_debugger)
print("We will hit a pause due to the ipdb!!")
ipdb.set_trace()
print("You won't see this unless we remove the ipdb.)
testing_the_debugger()
def testing_the_debugger():
before_the debugger = "You will see this!"
print(before_the_debugger)
print("We will hit a pause due to the ipdb!!")
import ipdb; ipdb.set_trace() // <-statement @ the breakpoint //
print("You won't see this unless we remove the ipdb.)
testing_the_debugger()
Wherever you choose your breakpoint to be, will be where you will need to add ipdb.set_trace().
To run the debugger, in your terminal, you will need to run python your file or file directory. Let say the example above was in a “lib” folder in the file named the_debugger.py, you would run python lib/the_debugger.py if outside the lib directory or python the_debugger.py if you were in the lib directory. Once ran, you should see something like this:
> python lib/the_debugger.py
You will see this!
We will hit a pause due to the ipdb!!
> /lib/the_debugger.py(6)testing_the_debugger()
5 import ipdb; ipdb.set_trace()
---> 6 print("You won't see this unless we remove the ipdb.)
7
ipdb>
The terminal shows you that you are in the ipdb shell with the last line. In the shell, you can run your code/s to make sure it works. The shell will return an error if there is something wrong, like a syntax error. To exit the shell, you type exit or CTL + D on your keyboard.
Although this might not seem like much, this lets you inspect all the code before the ipdb. So if something was not working properly, you will receive errors on your terminal. When you start to build more in-depth apps with multiple modules, being able to test each module individually will make finding errors less stressful and time consuming. You can also take debugging up a notch by building a separate module with the sole purpose of … well you guessed it, debugging.



In this example, these are all modules of the same app.
Instead of running ipdb on the individual modules, you can import your other modules to the debug module, create your variables there, and run the ipdb on your whole app.

This is the same app as the above example. Here you see that lib is the directory that holds startup.py, venture_capitalist.py and funding_round.py. With the statement on line one, you are importing everything in lib to the debug.py with the . Lines 5–13 are all variables of the modules and line 19 is our breakpoint, in this case it works with the whole app.*
As you start to read more on ipdb, you will find that there are also commands that you can use for a specific purpose. Here are a few examples. For a full list, check out skillhats.
h(elp): Prints a list of available commands or help about a specific command.w(here): Prints a stack trace, with the most recent frame at the bottom.s(tep): Execute the current line and stop at the first possible occasion.n(ext): Continue execution until the next line in the current function is reached.
Although I feel like I should have taken advantage of this earlier in my journey, I am hoping this will find you and help you succeed in yours.
Sources
- https://www.techtarget.com/searchsoftwarequality/definition/debugging#:~:text=A%20debugger%20is%20a%20software,of%20code%20were%20not%20executed.
- https://code.visualstudio.com/docs/editor/debugging
- https://nodejs.org/en
- https://docs.python.org/3/library/pdb.html#:~:text=The%20module%20pdb%20defines%20an,context%20of%20any%20stack%20frame.
- https://skillshats.com/blogs/debugging-made-easy-with-ipdb-the-python-debugger/#:~:text=ipdb%20is%20the%20IPython%2Denabled,magic%20functions%2C%20and%20much%20more.
메타데이터
- post_id
- 4c2e00757bad
- slug
- use-the-debugger-4c2e00757bad
- url
- https://medium.com/@sanohoang/use-the-debugger-4c2e00757bad
- canonical_url
- https://medium.com/@sanohoang/use-the-debugger-4c2e00757bad
- author_url
- https://medium.com/@sanohoang
- status
- ok
- fetched_at
- 2026-06-17 12:55:42