"Example code" is a computer programming concept.

Example code is source code which purports to demonstrate how to do something. Ideally, it should have clear, lavish comments, and it should introduce no concepts other than the one being demonstrated. It should be as brief as possible without being incomplete, and it should also compile and work. Ha ha. Even in an ideal case, example code usually just covers the most common case. That's the case it ought to cover, but if you're desperate enough to RTFM, that's usually not the case you need help with.

For example, documentation on an API function will often include a little snippet of code showing the function in use. Books about programming are often rife with example code. Example code found in programming books is often broken; sometimes it won't even compile. The likelihood of the code working runs in inverse proportion to the size of the author's photograph on the book. If there's no photograph of the author, other danger signs include the phrase "teach yourself foo in n (days|weeks)".

Like any documentation, example code tends to be obsolete, inaccurate, disinformative, and generally worse than useless.

Log in or register to write something here or to contact authors.