coding help
If debugging is the process of removing software bugs, then programming must be the process of putting them in.
—Edsger Dijkstra[1]

Debugging is the process of fixing problems ("bugs") in code. It is a normal part of the coding process.[2]

Computer bugs have existed for centuries. Programmer Ada Lovelace first wrote about them in 1843, though she didn't use the word "bug." Inventor Thomas Edison later used the term "bug" to refer to problems or engineering defects. (Though we don't know if he coined the term or if he heard it from someone else.) Famously, programmer Grace Hopper and her team found a dead moth stuck in the Mark II computer when it was malfunctioning. She later told the debugging story, helping popularize the term.[3][4]

Types of bugs

Bugs have two possible sources:[2]

A browser will try to fix missing closing HTML tags by adding them for you, but it may put them in the wrong place.[2]

Debugging strategies

Try re-reading documentation or online guides. Use human-written text (not AI), since this is more likely to be accurate.[5]

Sometimes, you might need to take a break. For example, if it's late at night, you might need to turn your brain off and on again. (This is also known as sleeping.) If it's not bedtime, maybe you need to get a drink of water or take a walk around the block. Returning with fresh eyes might be what you need.

If all else fails, and only a smaller part of your code is acting up, try deleting it entirely. Confirm that the bug is gone. Then rewrite the code from scratch. Sometimes, that's what it takes to rid yourself of a bug.

Rubber duck method

The "rubber duck" method is a popular way to debug code. Sometimes, expressing your problem in words can help you find the answer. But people aren't always available to listen. Here's how to use the rubber duck method:[6][7]

  1. Get a rubber duck (like the kind you use in a bathtub) and put it on your desk. If you don't have one, you can use something like a stuffed animal to be an honorary duck.
  2. Tell your rubber duck what your code is supposed to do, in general. Explain what is currently wrong with your code.
  3. Read your code line by line out loud. Explain to the duck what each line is supposed to do. Don't skip any details. (Remember, ducks can't read, so you must explain thoroughly.)

Eventually, as you tell your duck about the code, you'll notice something doesn't add up. There's a typo, or your code doesn't do exactly what you thought it did. There's your bug. Thank your duck and fix the bug.

Developers have been using this method for decades.

Temporarily changing your code

You can temporarily modify your code for debugging purposes. This includes things like:

Using the DOM inspector

See also: Inspect element
A menu after a user has right-clicked. The bottom option is Inspect.

Right-click and look for an "Inspect" option.

You can inspect the HTML and CSS of any webpage in your browser. This can be helpful for debugging your code.

Most browsers let you open the inspector by right-clicking. Right-click the element you want to look at. Then hit "Inspect" or "Inspect element" from the menu. This opens the DOM inspector.

The inspector will show you the HTML that builds the code. It'll also show the CSS that is being applied to the element. Navigate around and look for hints about what's going on.

You can also see if the console has logged any errors. These might help you understand what went wrong.

Best practices

Coding for easy debugging

Certain habits can help make debugging easier and less frequent. You can:

Start good habits. In HTML, type your closing tag right after typing your opening tag. This helps make sure you don't lose track of closing tags.

Avoiding or limiting AI

For more on AI and code, see Artificial intelligence.

Some websites recommend using artificial intelligence (AI) to debug your code. While it may help sometimes, it also often produces buggy code.[8]

Research on AI is still new. But studies so far find that it worsens your ability to think for yourself. When you use AI, you have less brain activity.[9][10] Your motivation fades.[11] These effects linger even after you stop using AI.[10][12][13] In fact, after people start and then stop using AI, their performance tends to be worse than it was before they started.[12]

If you want to grow or keep your coding and debugging skills, it's probably best not to use AI tools.

See also

External links

References

  1. Quote from AZ Quotes
  2. 2.0 2.1 2.2 Debugging HTML, MDN
  3. Edwards, Benj. What Is a "Computer Bug," and Where Did the Term Come From?, How To Geek
  4. Wills, Matthew. The Bug in the Computer Bug Story, JSTOR Daily
  5. Tech Vision. Stop Using AI, Use These Proven Coding Practices instead, Dev
  6. Rubber Duck Debugging, RubberDuckDebugging.com
  7. David. Rubber Duck Debugging: The Psychology of How it Works, Thoughtful Code
  8. Yepis, Erin. Developers remain willing but reluctant to use AI: The 2025 Developer Survey results are here, Stack Overflow
  9. Chow, Andrew. ChatGPT May Be Eroding Critical Thinking Skills, According to a New MIT Study, Time Magazine
  10. 10.0 10.1 Hulscher, Nicolas. MIT Study Finds Artificial Intelligence Use Reprograms the Brain, Leading to Cognitive Decline, Public Health Policy Journal
  11. Liu, Yukun, Suqing Wu, Mengqi Ruan, Siyu Chen and Xiao-Yun Xie. Research: Gen AI Makes People More Productive—and Less Motivated, Harvard Business Review
  12. 12.0 12.1 Bastani, Hamsa and Bastani, Osbert and Sungu, Alp and Ge, Haosen and Kabakcı, Özge and Mariman, Rei, Generative AI Can Harm Learning (July 15, 2024). The Wharton School Research Paper, Available at SSRN: https://ssrn.com/abstract=4895486 or http://dx.doi.org/10.2139/ssrn.4895486
  13. Kumar, Harsh, Jonathan Vincentius, Ewan Jordan, and Ashton Anderson. Human Creativity in the Age of LLMs: Randomized Experiments on Divergent and Convergent Thinking (PDF), arXiv