A few times I have told the anecdote that the singly most baffling thing I ever saw in a code review — not the most insecure, just the most “how could a real programmer have written this? how could this ever make sense?” thing — was simply a C++ variable “number_of_trucks” … declared as float. Unambiguously referring to real physical trucks in a fleet.

Reader, it’s been over ten years and I am blowing the gods damn whistle. I had edited that story to protect the guilty: the variable was named number_of_planes. It was shipped by a company whose name begins with “B” and rhymes with “GOING out of business.”

Also if you don’t know what a float is (because you’re not a programmer or have only worked with very high level languages that try to conceal these details) then my horror makes no sense so I will break it down for you

If you declare a number value to be a float, that is telling the computer two things:

  • first, that the value is allowed to be fractional and not just whole numbers (integers). This means that if someone reports that the fleet gained 2.3 planes or lost 0.01 planes, the computer would be like yeah, sure, that makes sense, let me write that down.

  • second, doing math with fractions is much more computationally complicated than whole numbers. Telling the computer a value is a “float” is explicitly telling it that you want it to use the fastest methods it has available to do the math, even if they’re not 100% accurate down to the smallest fraction of a fraction. You are saying it’s okay to lose track of a hundredth of a plane here or there as long as you count the planes really fast.

The intended use of floats is things like video game graphics: you can’t tell if the height of the enemy is 6.200002 meters or 6.2 meters exactly, and letting the computer not worry about the difference makes the calculations much faster. You should never, ever use floats for things like money, because over the course of many successive adds and subtracts, entire cents or dimes will just pop in and out of existence. Or, like, some unspecified fraction of a plane, which is probably not what you want.

@0xabad1dea it would make sense for ships, though. Because you know, they float.