This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.

Title

ELI5 answer to: How and why do computer programs crash?

Description

ELI5 is the "Explain LIke I'm Five" forum at <a href="http://reddit.com">Reddit</a>. I recently answered the question "How and why do computer programs crash?" and thought the answer might be worth cross-posting (even though the <a href="http://www.reddit.com/r/explainlikeimfive/comments/1uew5z/eli5_how_and_why_do_computer_programs_crash/">post</a> itself never gained any traction). <h>What is a program?</h> Programs comprise a limited set of instructions that tell them what they should do when they encounter certain inputs under certain conditions. <h>Who writes programs?</h> People write computer programs. Therefore, programs only do what those people can anticipate. Unanticipated situations result in crashes. <h>Anatomy of a crash</h> A "crash" is when a program is no longer able to process further input. Here's roughly how it works: <ul> The environment in which the program runs applies input events to the program. The program checks for an instruction that matches its current state plus the new input. If one is found, it applies that instruction to create a new, current state. A program "crashes" when it receives an input in a given state that it was not designed to handle. </ul> <h>Different kinds of crashes</h> This can happen either: <ul> When the program enters an infinite loop and is no longer capable of responding to new input (sometime called "hanging"). When the program terminates itself as a result of not being able to handle the input ("hard crash" or "unhandled exception" or "segfault", etc.). </ul> This does not mean that the program behaves unpredictably. The crash is perfectly predictable. <h>Avoiding crashes</h> Crashes can be avoided with one or more of the following: <ul> Good design Good programmers Good libraries & programming languages Good testers Time Money </ul> Hope that helps.