Lesson 8: Debugging Is Development: Learning How to Fix What Breaks
Debugging Is Development: Learning How to Fix What Breaks
After spending our previous sessions learning about databases, GitHub and Agile development, our next class focused on something every programmer eventually becomes very familiar with: debugging.
When learning to program, it is easy to think that experienced developers simply write code that works the first time. In reality, a large part of software development is identifying problems, understanding why they happened, and systematically working toward a solution.
For this session, our main goal was simple: get everyone's development environment working and make sure every student could run the project locally.
What Is Debugging?
Debugging is the process of finding and fixing problems in software.
A bug might be something obvious, such as a page refusing to load, or something more subtle, such as a form submitting successfully but saving the wrong information.
Good debugging is not about randomly changing code until something works. Instead, we want to follow a process:
- Read the error message.
- Identify where the error occurred.
- Understand what the program expected.
- Compare that with what actually happened.
- Make one logical change.
- Test again.
This is one of the most important habits a new developer can learn.
Getting Everyone Running
Because every student's computer can be slightly different, we worked through several common development problems.
These included things such as:
- Python not being installed correctly.
- Virtual environments not being activated.
- Missing Python packages.
- Django projects being opened from the wrong directory.
- Database migrations not being applied.
- URL configuration problems.
- Template errors.
- Typos and syntax errors.
These problems may seem frustrating at first, but they provide excellent opportunities to understand how all the pieces of a development environment work together.
Reading Django Error Messages
Django provides detailed error pages when something goes wrong during development.
At first, these pages can look intimidating because they contain a large amount of technical information. The key is learning which parts matter most.
We focused on three important pieces:
- Exception Type — the general category of error.
- Exception Value — a description of what went wrong.
- Traceback — the path the program followed before reaching the error.
The traceback is especially useful because it often tells us the exact file and line of code where Django encountered the problem.
Errors Are Information
One of the biggest mindset changes in programming is learning not to treat error messages as failure.
An error message is information.
Instead of thinking:
"My program is broken."
we can begin thinking:
"The computer is telling me exactly where it became confused."
That small change in perspective makes debugging much easier.
Learning to Search for Solutions
Professional developers do not memorize every programming command or every possible error message.
Instead, they become very good at finding information.
When researching an error, it helps to search for the most specific part of the message rather than describing the entire problem.
For example, searching for:
NoReverseMatch Django
will usually produce much better results than searching:
my django website doesn't work
Learning how to ask good technical questions is an important programming skill on its own.
Why This Session Matters
Although we did not add many new features during this class, the session was important because software development depends on being able to diagnose problems independently.
As our applications become larger, bugs will become more complicated. Developers need to be comfortable reading error messages, tracing program execution and testing possible solutions.
By the end of the session, we had everyone's environment much closer to the same starting point and were ready to continue building our largest project yet: a Youth Job Bank.
Key Concepts
- Debugging is a normal part of programming.
- Error messages contain useful information.
- Make one change at a time when troubleshooting.
- Use tracebacks to locate problems.
- Developers need to know how to research unfamiliar errors.
- A working development environment is the foundation of every software project.
With our development environments running, we were ready to move beyond individual programming exercises and begin connecting everything we had learned into a real application.
In this series
- 1. Lesson 1: Thinking Like a Builder
- 2. Lesson 2: Building Our First Multi-Page Website with HTML and CSS
- 3. Lesson 3: Beginning Programming with Python
- 4. Helper text
- 5. Lesson 4: Connecting Some Dots
- 6. Lesson 5: The Team Environment and a Taste of Embedded
- 7. Lesson 6: From Databases to Development Teams: MySQL, GitHub and Agile
- 8. Lesson 8: Debugging Is Development: Learning How to Fix What Breaks
- 9. Lesson 9: Building a Real Django Application: The Youth Job Bank
- 10. From First-Time Coders to a Working Prototype