Email or username:

Password:

Forgot your password?
abadidea

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.”

25 comments
Pete Alex Harris🦡🕸️🌲/∞🪐∫

@0xabad1dea

But now it makes sense. Number of planes can go from 1.0 to 0.99 in flight.

Grissallia

@0xabad1dea who amongst us hasn't found that we've got 3874.297 planes?

J Davis 🕊️🧭🌈🎱🦀

@grissallia @0xabad1dea
@petealexharris

A comment above yours leads me to believe that of the 3874.297 planes there are 703 that have lost that .01 door panel. I could be wrong. I'm bad at this technical stuff.

Tom Forsyth

@0xabad1dea I was about to laugh along with you, but from the clues you gave, that is the exact company where a fractional number of planes is a very useful everyday metric.

Mac Berg

@0xabad1dea Oooh, that's smart! They made sure to have the software ready for partial planes, losing emergency doors and stuff. Ahead of their time, really.

Biggles

@0xabad1dea my irrational number of completed planes - Pi or e planes completed, we're not really sure how complete the partial one is

Legit_Spaghetti

@0xabad1dea Everyone talking about how silly it is to use a float when they shoulda used an int, and I'm over here thinking unsigned int probably would have made even more sense, unless company was expecting to have fewer than zero planes at some point.

abadidea

@Legit_Spaghetti unfortunately it’s extremely common to use the negative integer space to encode error states, which tends to cause its own problems, but seeing them do that would have fallen within the normal range of incorrect for me

Johann-Tobias Schäg

@0xabad1dea @Legit_Spaghetti With floats we can do NaN encoding fun ♥️
like NaN because it's not a plane.

Baz Scott

@0xabad1dea I worked at a large investment bank years ago where all currencies were stored as floats EXCEPT GBP which was store as Ints in pence. (Yes, even Yen that has no fractional value).

Of course, on occasion, some programmer would forget to * or / by 100 to get GBP and all hell would break loose 😂

It rhymed with Reddit and a European Alpine country with a square flag who DID go bust 😂

sotolf

@0xabad1dea I'm just waiting for you to learn about javascript and lua :p

Zipkid

@0xabad1dea That one truck got hit by a train and only a fraction remained...

Bruce Heerssen

@0xabad1dea Are you certain that Boeing planes can't exist as fractions?

abadidea

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.

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:

ƒ

@0xabad1dea Sounds like the perfect use case for Boeing then. That door did pop out of existence, after all.

DCoder🇱🇹❤🇺🇦

@0xabad1dea
Floats also allow some languages to write cool documentation like “If <language> encounters a number beyond the bounds of the int type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the int type will return a float instead.” 🙃

Thomas Sturm

@0xabad1dea @designatednerd Really very forward looking to allow for incomplete planes. 😁

Spring Breakdown :jo:

@0xabad1dea I feel like programmers need that thing like engineers having a ring made out of a bridge fragment or some shit to remind them of what might happen if they fuck up.

[BUG] Lunya :3

@0xabad1dea They were actually playing 4D chess right in front of your eyes. If a plane doesn't have its door plug, can you really consider it a whole plane? No. If you had approved that pull request then B***ng would still be thriving.

abadidea

@lunacb oh it was already in production by the time I saw it 😂 I’m a third party independent opinion type reviewer

Joshua Barretto

@0xabad1dea "Hello, sir, I'd like NaN planes please"

Statements dreamed up by the insane

Go Up