Integer as a Metaphor

The humble `integer` type shows how a single word in programming can participate in two Metaphor Systems.

A Machine Word Is a Mathematical Integer

The integer type is a metaphor that links together a fixed-size computer word and a mathematical structure. So the Source Domain is an abstract mathematical construct, and the Target Domain is a sequence of bits that acts kinda-sorta like a mathematical integer:

Here's a picture:

(Double-click to enlarge)

Because the target domain has no notion of boundaries to integers, reasoning doesn't take that into account unless it gets a jolt.

A Machine Word Is a Container

However, when an `int` variable is viewed as a container, that introduces the possibility of overfilling it – integer overflow.

That's a different source domain, which helps the programmer think more clearly: *if reminded to think about it at all*.

The Off-By-One Error

Of the two metaphors, the very name of the type (`int`) activates the first one. There are no words in the program (usually) to activate the second. So the implications of overflow literally "do not come to mind" most of the time. Hence: bugs.

In normal use of metaphor (Real Metaphors Are Promiscuously Mixed), a speaker would add metaphors from different metaphor systems as needed. This is less of a possibility in programs. There's no effective way to point at a particular integer and say, "Remember this is a Container."