Q: Who first described the "fence-post error?"

A: I don't know, but I have a good candidate: Vitruvius

I haven't done a lick of research on this unimportant question, but recently I happened to come across an interesting early description of this well-known pitfall for the unwary programmer. I decided to post it and see if anyone can find an earlier published reference on the topic.

The fence-post error is also known as the "off-by-one" error. The more colorful term comes from a simple trick question that illustrates the error: if you are building a fence with fence posts that are 10 feet apart, and you want to build the fence to be 100 feet long, how many fence posts do you need? The answer, of course, is 11, not 10. The fence needs to have 10 intervals between posts, and the extra post is needed to begin the first interval.

Vitruvius was a contemporary of Julius Caesar who wrote a book misleadingly titled "On Architecture." I say this title is misleading since the book includes much more than just architecture, including the story of Archimedes' "eureka" moment, comments about plagiarism, some descriptions of early metallurgical processes, an early approximation to π, a suggestion for reforming the funding of public works, and many other interesting facts and comments.

Here is what Vitruvius had to say about the fence-post error:

In araeostylis enim libertas est quantum cuique libet constituendi. Sed ita columnae in peripteris conlocentur uti quot intercolumnia sunt in fronte, totidem bis intercolumnia fiant in lateribus. Ita enim erit duplex longitudo operis ad latitudinem. Namque qui columnarum duplicationes fecerunt erravisse videntur, quod unum intercolumnium in longitudine plus quam oportet procurrere videtur.*

For those more proficient in English than Latin, here is the Gwilt translation, which can be found complete at Bill Thayer's Lacus Curtius site.

In the araeostylos [style of temple] it is only necessary to preserve, in a peripteral building, twice the number of intercolumniations on the flanks that there are in front, so that the length may be twice the breadth. Those who use twice the number of columns for the length, appear to err, because they thus make one intercolumniation more than should be used.

In this section of the book Vitruvius is describing the best way to space the columns around a temple. The passage quoted here is addressing how to construct a temple whose length is twice its breadth. If the columns are equally spaced, the solution is to subtract one from the number of columns along the breadth (giving the number of intercolumniations), double that, and add one to yield the number of columns along the length.

If anyone knows of an earlier reference to this issue, please let me know and I'll update this page.

*Vitruvius, De Architectura, Book 3, Chapter 4.

To top of document





back Back to my Opinions page

up Up to My Home Page