Debugging and Refactoring
Explore how to use GitHub Copilot to identify and fix runtime bugs, refactor long functions into smaller parts, and convert procedural code into organized classes. This lesson helps you enhance code readability, maintain functionality, and solve logic errors effectively.
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.
Task:
Run this code locally.
Open ...