第一個「真正的」bug 是一隻飛蛾:至今仍適用的 4 個除錯步驟
The first "actual" bug was a moth: 4 debugging steps that still work
1947 年,工程師在 Harvard Mark II 電腦的繼電器內發現一隻飛蛾,並記錄為「First actual case of bug being found」;這則故事令 Grace Hopper 聞名,但「bug」一詞早在此之前已用來指故障。除錯可分為 4 個步驟:穩定重現問題、逐步縮小範圍、記錄發現,以及驗證修正。用橡皮鴨逐行解釋程式碼,也可能幫助找出問題。
Why do we call software problems "bugs"? Part of the story involves a real moth.
On September 9, 1947, Harvard's Mark II computer malfunctioned. Engineers traced the fault to a relay, found a moth stuck inside, taped it into the logbook and wrote: "First actual case of bug being found."
That logbook page is now at the Smithsonian's National Museum of American History. Computing pioneer Grace Hopper, who worked on the team and later helped drive the creation of COBOL, made the story famous.
The fun twist: "bug" already meant a fault long before 1947. Edison used the word in the 19th century. So the note was an engineer's joke: this time it was an actual bug.
Debugging still follows the same four steps:
- Reproduce it reliably. "Sometimes it happens" is the hardest bug to catch.
- Narrow it down by halves, like a guessing game.
- Write down what you find, just like that logbook page.
- Verify the fix. Run it again and confirm it is really gone.
Bonus: rubber-duck debugging. Put a rubber duck on your desk and explain your code to it line by line. Halfway through, you often spot the problem yourself. The trick comes from The Pragmatic Programmer, and it is ridiculously simple, but it works.
What's the weirdest bug you've ever caught?
(Some images AI-generated)
來源:DEV Community · dev.to