The Most Logically Flawless Case of Undefined Behavior
Description
A screenshot of a Twitter thread discussing a humorous piece of old tech documentation. The main tweet by JF Bastien reads, 'Probably the best Undefined Behavior, ever,' referring to a snippet from the BeOS API. The snippet, originally shared by Slava Pestov, shows documentation for two C-style functions. The first, 'is_computer_on()', is described as: 'Returns 1 if the computer is on. If the computer isn't on, the value returned by this function is undefined.' The second, 'is_computer_on_fire()', 'Returns the temperature of the motherboard if the computer is currently on fire. Smoldering doesn't count.' The humor lies in the perfect, albeit absurd, logical trap of the 'is_computer_on' function - it's impossible for the function to execute and return a value if the computer is off, making its behavior truly 'undefined'. For senior developers, this is a high-level joke that touches upon formal language specifications (like in C/C++), logical paradoxes in computing, and nostalgia for the quirky APIs of older, niche operating systems like BeOS
Comments
21Comment deleted
This is the original Schrödinger's function. You can't know the state of the computer without observing it, but observing it requires it to be in the 'on' state, collapsing the waveform of possibilities into a segmentation fault
BeOS declares is_computer_on() undefined when the box is off, so the optimizer is free to assume infinite uptime - finally a spec that meets the VP’s “five nines or you’re fired” SLA
After 20 years in tech, I've finally found the API that perfectly captures production monitoring: it confidently tells you the server is on fire, but can't guarantee it knows if it's actually running. This is basically every health check endpoint I've ever written, just more honest about it
It's the only UB spec with a rigorous proof of correctness: if you can read the return value, it returned 1. The fire variant, meanwhile, is the industry's most honest SLO - 'some other value' describes most of our monitoring dashboards
This is the programming equivalent of 'if a tree falls in the forest and no one is around to hear it' - except here, if your computer is off, you can't call the function to find out it's off, and if you somehow could, the return value is undefined anyway. It's Schrödinger's API: the computer is simultaneously on and off until you observe it, but observation requires it to be on. BeOS engineers were clearly operating on a higher plane of existence - or perhaps they just wanted to ensure their error handling was truly exceptional by making it metaphysically impossible
BeOS fixed UB by deferring to hardware reality: if the box is off, who cares what the compiler summons?
Because UB lets the optimizer assume impossible branches never happen, is_computer_on() can be constant‑folded to 1 - turns out undefined behavior is a renewable power source
BeOS is_computer_on(): returns 1; else undefined - the only health check that implements proof by contradiction via undefined behavior. If you can read the result, QED
this is a joke, right? Comment deleted
is_computer_exist() Comment deleted
когда учил язык на скайкенг Comment deleted
1. is (it true that) computer (does) exist 2. use english in this chat or add a translation Comment deleted
Why you can't just add translator bot like this: @TgTranslatorBot ? Comment deleted
auto translator is shit Comment deleted
I agree Comment deleted
Anyway it's much better than case when someone who doesn't know English trying to text something Comment deleted
В чужой монастырь со своим уставом не ходят. In the Rome do as the Romans do. how will you detect which text should be translated and which not? Comment deleted
I'm not sure how exactly this bot detects messages and which part of it should be translated. Comment deleted
So it sounds more like a pretense Comment deleted
also multilingual text is gonna to get fucked up Comment deleted
How did u know Comment deleted