Skip to content
DevMeme
3826 of 7590
Languages Post #4168 · source on Telegram

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

21
Anonymous ★ Top Pick 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
  1. Anonymous ★ Top Pick

    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

  2. Anonymous

    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

  3. Anonymous

    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

  4. Anonymous

    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

  5. Anonymous

    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

  6. Anonymous

    BeOS fixed UB by deferring to hardware reality: if the box is off, who cares what the compiler summons?

  7. Anonymous

    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

  8. Anonymous

    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

  9. @beton_kruglosu_totchno 4y

    this is a joke, right?

  10. @niklody 4y

    is_computer_exist()

    1. @revocat 4y

      когда учил язык на скайкенг

      1. @sylfn 4y

        1. is (it true that) computer (does) exist 2. use english in this chat or add a translation

        1. @lvanPetr0v 4y

          Why you can't just add translator bot like this: @TgTranslatorBot ?

          1. @sylfn 4y

            auto translator is shit

            1. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

              I agree

            2. @lvanPetr0v 4y

              Anyway it's much better than case when someone who doesn't know English trying to text something

              1. @sylfn 4y

                В чужой монастырь со своим уставом не ходят. In the Rome do as the Romans do. how will you detect which text should be translated and which not?

                1. @lvanPetr0v 4y

                  I'm not sure how exactly this bot detects messages and which part of it should be translated.

            3. @lvanPetr0v 4y

              So it sounds more like a pretense

          2. @sylfn 4y

            also multilingual text is gonna to get fucked up

  11. @niklody 4y

    How did u know

Use J and K for navigation