Skip to content
DevMeme
2991 of 7590
Languages Post #3303 · source on Telegram

The Four Stages of Writing 0.5 in Code

Description

A four-panel 'Expanding Brain' meme illustrating progressively more obscure ways to represent the number 0.5 in programming. The first panel shows '1/2' next to a simple brain scan, representing the most basic fractional form. The second panel displays '0.5' with a slightly more illuminated brain, the standard decimal notation. The third panel shows '.5', a common code shorthand, with an even brighter brain. The final panel, representing the highest level of enlightenment or 'galaxy brain,' shows the expression 'TRUE / 2' next to a brain radiating pure energy. The humor is aimed at developers who understand type coercion, where in many languages the boolean value 'TRUE' is implicitly cast to the integer 1, making the expression evaluate to 0.5. It's a joke about discovering language quirks and writing 'clever' code that is often unreadable and considered bad practice, despite being technically correct

Comments

50
Anonymous ★ Top Pick The final panel is how you write 0.5 when your goal is to make the next developer who maintains your code question their career choice during a pull request
  1. Anonymous ★ Top Pick

    The final panel is how you write 0.5 when your goal is to make the next developer who maintains your code question their career choice during a pull request

  2. Anonymous

    Peak engineering: express 0.5 as (true / 2) so the compiler and the next maintainer both experience implicit coercion

  3. Anonymous

    This is the same code that passed review because the senior who wrote it 'has been doing JavaScript since before you were born' and insists that truthy division is a valid performance optimization

  4. Anonymous

    The real galaxy brain move is when you realize that in JavaScript, (true / 2) === 0.5 but (true + true) / 2 also equals 1, making boolean arithmetic the most elegant way to confuse junior developers during code reviews while technically being completely valid. It's the programming equivalent of 'just because you can, doesn't mean you should' - a principle we all learned after that one time we chained 47 ternary operators because we thought it made us look clever

  5. Anonymous

    TRUE/2: the half-truth every JS dev lives by

  6. Anonymous

    TRUE/2 is the quickest way to make JS and Python tests green, Go fail the build, Rust file a grievance, and your next code review add “no implicit coercion” to the lint rules

  7. Anonymous

    Lint bans magic numbers? Fine - use TRUE/2; it’s self-documenting, leverages type coercion, and accurately describes the codebase: a half‑truth

  8. Deleted Account 5y

    the problem is that true is not always equal to 1

    1. @prirai 5y

      No

  9. @prirai 5y

    Any number except zero can be true

  10. @prirai 5y

    But true is always one.

    1. Deleted Account 5y

      in what programming language ?)

      1. @RiedleroD 5y

        I don't know of any programming lang where true is not 1. However, some don't allow implicit conversions.

      2. @kitbot256 5y

        If you convert 5 to Boolean, you get True if you convert True to Integer, you get 1 Works in Python and JS. I didn't check other languages.

      3. @zherud 5y

        You can print(true+1) in almost any language and get 2: C++,java,python... But there is also Ruby and maybe smth else where true works strange.

    2. @armanokka 5y

      Really

  11. @Fatimel 5y

    syka eshe raz takyuy huety pizdanete......

    1. @Dobreposhka 5y

      *suka yeshyo raz takuyu huyetu pizdanyotye...

      1. @RiedleroD 5y

        please talk english or provide a translation to your text

        1. @Dobreposhka 5y

          i just corrected the guy above. Here's the translation: fuck, if you fucking say that fucking thing just one more time...

          1. @RiedleroD 5y

            it's alright, I didn't warn either of you

      2. @Fatimel 5y

        thanks

    2. @RiedleroD 5y

      you too

    3. @VlP_AI_TG 5y

      Ooo, vi tozhe iz anglii?))

      1. @VlP_AI_TG 5y

        Translate: Ooo, you are from england too

  12. @bommelhopser 5y

    I can‘t deal with the fact that non-null objects are TRUE in php…

    1. @kitbot256 5y

      you can deal with the fact in Ruby if you like. Also in Ruby 0 is True.

      1. @RiedleroD 5y

        fuck ruby ngl

        1. @kitbot256 5y

          ngl?

          1. @RiedleroD 5y

            not gonna lie

            1. @kitbot256 5y

              thanks, I didn't know this one. And speaking of 0 == True in Ruby, IMHO you shouldn't rely on implicit conversions too much. Explicit may be a bit slower to work with, but it is less likely to present some bugs.

              1. @RiedleroD 5y

                aye, I absolutely agree. Still, fuck ruby

        2. @Agent1378 5y

          Ruby is fine. Rails are fucked though

  13. @prirai 5y

    Some languages are value specific and don't have booleans like C. Others accomodate booleans too and are boolean strict.

  14. @prirai 5y

    While the likes of python don't allow interconversion at all. (Unless a module is used.)

    1. @RiedleroD 5y

      python does allow some implicit conversions. True/2==0.5 in python.

  15. @feskow 5y

    true * 0.5

  16. @ryudoge 5y

    ooo kurwa

  17. @nn_private 5y

    #define TRUE 666

  18. @sylfn 5y

    just use true / (double)(true << true)

  19. @azizhakberdiev 5y

    Does in any language .5 work?

    1. @sylfn 5y

      in Russian it doesn't

      1. @spiritualattunement 5y

        Ерiс

    2. @Dobreposhka 5y

      css

  20. @scout_ca11sign 5y

    1. >> 1

    1. @sylfn 5y

      I dont think that will work as bit shift is performed on integers, not decimals. At least in Python 3, it gives me an error

      1. @scout_ca11sign 5y

        well yeah, you could (theiretically) do it with integer to get 5, and then use casting magic to turn it into 0.5, but that is cursed as hell

        1. @feskow 5y

          someone said casting magic? double d = 1.0; long long temp = ( (*(unsigned long long*)&d) & ~0x7ff0000000000000) | ( ( ( (*(unsigned long long*)&d) >> 52) - 1) << 52); d = *(double*)&temp; std::cout << d << std::endl;

          1. @scout_ca11sign 5y

            Carmack detected

          2. @affirvega 5y

            you can try it out online https://godbolt.org/z/8nqEv5bjW

Use J and K for navigation