Debug

| Anti-Pattern | Why It's Wrong | The Fix | | :--- | :--- | :--- | | | Changing code without understanding creates new bugs. | Form a hypothesis first. | | The Print Spam | print("here") 50 times tells you nothing useful. | Print variable values and context. | | The Blame Game | "It must be the library/OS/compiler." (It rarely is.) | Assume your code is wrong first. | | The Single Snapshot | Looking at one failure in isolation ignores patterns. | Look for 3-5 occurrences. |

We are entering an era where machine learning assists debugging:

So, how do you debug effectively? Here's a step-by-step guide: | Anti-Pattern | Why It's Wrong | The

Multi-threaded operations access shared data simultaneously.

When you can’t run a debugger in production (which is most of the time), rely on logs and metrics: | Print variable values and context

: For Jekyll users, posts may be ignored if the filename uses underscores instead of hyphens (e.g., use 2024-11-01-post.md instead of 2024_11_01_post.md ).

This refers to troubleshooting why a blog post isn't appearing or rendering correctly on a site: | Look for 3-5 occurrences

Based on evidence, propose a cause. “I think calculate_total() receives a negative quantity because the input validation is missing.” A good hypothesis is falsifiable.

Prove or disprove your theory. Use tools to inspect variables, track data flow, and pause execution at critical moments. If your hypothesis is proven wrong, form a new one based on the new data collected. Step 5: Implement and Verify the Fix

Before we discuss how to debug, we must define the scope. The word "debug" means to identify, isolate, and eliminate a defect (bug) that causes software to behave unexpectedly. However, modern technologists have expanded this definition.