Debugging and Refactoring
Explore how to identify and fix runtime bugs using Copilot chat, refactor complex functions into simpler parts, and reorganize procedural code into classes. Understand techniques for improving code readability and maintainability while preserving functionality through guided hands-on challenges.
We'll cover the following...
Why debug and refactor?
Even with solid unit tests, bugs can still sneak into the runtime. Debugging is about finding and fixing those issues. Refactoring, however, focuses on improving messy or overly complex code, which helps prevent future bugs and makes the code easier to maintain.
Note: Refactoring isn’t just about cleaning code; it makes it faster for new developers to read, understand, and contribute. Well-organized code helps teams move quicker and onboard new teammates with less confusion.
Runtime error hunt
Let’s explore how to find and fix bugs affecting your program during runtime.
Bug scenario: Infinite loop in triple while nest
Here’s a classic example where a missing update creates an infinite loop—let’s debug it together.