What Is a Bug
A bug is a mistake in a program that makes it behave wrongly — produce a wrong answer, do the wrong thing, or stop working — and it exists because, as the how-programs-run topic established, a computer follows its instructions exactly, so when the instructions are wrong the computer faithfully does the wrong thing without any idea that a mistake was intended. The word is famously said to come from a real moth found stuck in an early computer in 1947, but the important point is conceptual: a bug is almost never the hardware malfunctioning and almost always a human error frozen into the program's instructions — a step in the wrong order, a forgotten case, a mistaken assumption about the data. Bugs come in a few recognizable kinds. A syntax error is a mistake in the grammar of the programming language — a missing bracket or misspelled keyword — and it usually stops the program from running at all, the way a sentence with scrambled punctuation fails to parse; these are the easiest bugs because the tools from the how-programs-run topic, the compiler or interpreter, catch them and point to the line. A runtime error happens while the program is running — it starts fine, then hits something impossible, like dividing by zero or trying to open a file that is not there, and crashes partway through. The hardest kind is a logic error: the program runs to completion and crashes nothing, but the instructions, though valid, compute the wrong result — it calculates a total incorrectly or sends the message to the wrong person — and nothing flags it, because from the computer's point of view it did exactly what it was told. Finding and fixing bugs is called debugging, and it is a disciplined process rather than random guessing: reproduce the problem reliably so you can see it happen on demand, narrow down where it occurs by checking the program's state at points along the way (often by having it print what it is doing, or by stepping through it one line at a time with a tool called a debugger), form a hypothesis about the cause, fix it, and then confirm the fix actually worked and did not break something else. This is exactly why the testing stage from the how-apps-are-made topic exists: tests try the program on many inputs on purpose, so that logic errors in particular are caught by the team before users ever meet them. The reassuring truth is that bugs are normal and universal — every non-trivial program ever written has had them, and professional software development is in large part the ongoing craft of preventing, finding, and fixing them — so a bug is not a sign that something mysterious went wrong, but simply a human mistake in the instructions, waiting to be located and corrected.