A-Z of the digital world
Monday 29 July 1996
Hackers and computer scientists, unwilling to let their obsessions remain computer-based, often like to call the first chapter of a publication "Chapter 0", especially if it is of an introductory nature: one of the classic instances was in the first edition of Brian Kernighan and Dennis Ritchie's book The C Programming Language. In recent years this trait has also been observed among many pure mathematicians (who have an independent tradition of numbering from 0, and getting into fights after a few beers in bars over what sort of integer zero is).
Zero-based numbering does actually have real usefulness: it reduces the likelihood of "fencepost errors", which can easily occur in programs that repeat a calculation until some boundary condition is true - that is, perform an "iterative loop".
Fencepost errors are so named from the problem known to settlers in the Wild West: how many posts are needed to build a fence 10 metres long with 1 metre between each post? (Clue: the answer is not 10.) Or suppose you have a long list of items, and want to process items m through n: how many items are there to process? The obvious answer is n-m, but that is off by one; the right answer is (n-m+1). A program that used the "obvious" formula would have a fencepost error in it. However, if you rest the list of items to be processed into an array that started numbering at 0, you wouldn't. Which is why sometimes it's better to be zeroth than first.
Life & Style blogs
Windows 10: man updates PC, wakes up to find porn slideshow on repeat
Free porn websites could be shut down within months, says David Cameron
National Orgasm Day: Six reasons (plus one bogus one) why they're good for us
The 'world's most beautiful vagina' has been debunked by science
What do the emojis on Snapchat mean?
Yvette Cooper: Our choice is years of Tory rule under Jeremy Corbyn – or a return to a Labour government
Labour leadership contender Jeremy Corbyn says 'we can learn a great deal from Karl Marx'
Is Britain really full up? Are migrants taking our jobs? Leading academic answers the most common anti-immigration claims
Calais Migrant Crisis: Deputy Mayor of Calais labels Cameron's use of 'swarm' as 'racist' and 'ignorant'
Public anger after French sunbather beaten up by gang for wearing a bikini in Reims park
Labour leadership: New poll shows party is now even 'less electable' than under Ed Miliband
- 1 Windows 10: man updates PC, wakes up to find porn slideshow on repeat
- 2 The 'world's most beautiful vagina' has been debunked by science
- 3 John Green schools morning show hosts after awkward interview with Cara Delevingne
- 4 Supermodel Gisele Bundchen mocked for wearing a burka to avoid being seen visiting plastic surgeon in Paris
- 5 Bulletproof armadillo puts Texas man in hospital after shot bounces off hard shell
£17000 per annum: Recruitment Genius: They are a leading company in the field ...
£30000 - £35000 per annum: Recruitment Genius: This is an exciting opportunity...
£26041 - £34876 per annum: Recruitment Genius: There has never been a more exc...
£14000 - £17000 per annum: Recruitment Genius: The fastest growing travel comp...