site banner

Friday Fun Thread for August 2, 2024

Be advised: this thread is not for serious in-depth discussion of weighty topics (we have a link for that), this thread is not for anything Culture War related. This thread is for Fun. You got jokes? Share 'em. You got silly questions? Ask 'em.

1
Jump in the discussion.

No email address required.

And I'm shouting "it's the demons!" with a crazed look in my eyes, cuz I don't fuckin know how it happens.

I shout "it's the demons!" all the time because that's the traditional example of how it happens.

A coworker writes code with Undefined Behavior. I point out that the C or C++ standard says the compiler is now allowed to let their executable do anything, including make demons fly out their nose. They point out that their code passed a couple tests. I point out that the nasal demons are actually still a best case scenario, because "anything" also includes "passing tests selectively or temporarily".

The worst case scenario is also a typical scenario: the UB works at first, but then in a couple months or years someone uses a different CPU type, or a linker goes to a different object file first, or a compiler gets a more aggressive optimizer, or an updated library leaves the heap in a different state, or a different thread starts winning races, etc. and then the code starts obviously breaking, out in the wild, where if we're lucky it is now crashing and making users scream at us or if we're unlucky it is just producing silently corrupted results, and where in either case the original concern has long been forgotten and the debugging will have to rediscover it from scratch.

And one might read that and smugly think "so don't use C/C++", but they're actually much better about UB than most dependencies. UB in C++ is "you wrote code clearly described as UB in a 300 page standards doc", but in most libraries it's "the API and the scraps of documentation said you needed to do 'X' but the developer really meant you needed 'W,X,Z' and if you did 'W,X,Y' instead you'll start breaking after the update next July, which you can't avoid because it's the only bugfix for a corner case your users started hitting in May"!

(I try to explain this without getting a crazed look in my eyes; success rates vary.)