Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. Tell me the truth ...

Tell me the truth ...

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
32 Posts 20 Posters 3 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T [email protected]

    Well there are containers that store booleans in single bits (e.g. std::vector<bool> - which was famously a big mistake).

    But in the general case you don't want that because it would be slower.

    E This user is from outside of this forum
    E This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #11

    Why is this a big mistake? I’m not a c++ person

    B 1 Reply Last reply
    0
    • E [email protected]

      Why is this a big mistake? I’m not a c++ person

      B This user is from outside of this forum
      B This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #12

      The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways.

      E 1 Reply Last reply
      0
      • B [email protected]

        The mistake was that they created a type that behaves like an array in every case except for bool, for which they created a special magical version that behaves just subtly different enough that it can break things in confusing ways.

        E This user is from outside of this forum
        E This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #13

        Could you provide an example?

        T 1 Reply Last reply
        0
        • cm0002@lemmy.worldC [email protected]
          This post did not contain any content.
          M This user is from outside of this forum
          M This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #14

          This reminds me that I actually once made a class to store bools packed in uint8 array to save bytes.

          Had forgotten that. I think i have to update the list of top 10 dumbest things i ever did.

          rikudou@lemmings.worldR 1 Reply Last reply
          0
          • M [email protected]

            Apart from dynamically typed languages which need to store the type with the value

            You know that depending on what your code does, the same C that people are talking upthread doesn't even need to allocate memory to store a variable, right?

            H This user is from outside of this forum
            H This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #15

            How does that work?

            T 1 Reply Last reply
            0
            • cm0002@lemmy.worldC [email protected]
              This post did not contain any content.
              houseofleft@slrpnk.netH This user is from outside of this forum
              houseofleft@slrpnk.netH This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #16

              Wait till you here about every ascii letter. . .

              A 1 Reply Last reply
              0
              • houseofleft@slrpnk.netH [email protected]

                Wait till you here about every ascii letter. . .

                A This user is from outside of this forum
                A This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #17

                what about them?

                houseofleft@slrpnk.netH 1 Reply Last reply
                0
                • A [email protected]

                  what about them?

                  houseofleft@slrpnk.netH This user is from outside of this forum
                  houseofleft@slrpnk.netH This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #18

                  Ascii needs seven bits, but is almost always encoded as bytes, so every ascii letter has a throwaway bit.

                  V 1 Reply Last reply
                  0
                  • houseofleft@slrpnk.netH [email protected]

                    Ascii needs seven bits, but is almost always encoded as bytes, so every ascii letter has a throwaway bit.

                    V This user is from outside of this forum
                    V This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #19

                    Let's store the boolean there then!!

                    A 1 Reply Last reply
                    0
                    • cm0002@lemmy.worldC [email protected]
                      This post did not contain any content.
                      J This user is from outside of this forum
                      J This user is from outside of this forum
                      [email protected]
                      wrote on last edited by
                      #20

                      Wait until you hear about alignment

                      B 1 Reply Last reply
                      0
                      • T [email protected]

                        No it isn't. All statically typed languages I know of use a byte. Which languages store it in an entire 32 bits? That would be unnecessarily wasteful.

                        A This user is from outside of this forum
                        A This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #21

                        It's not wasteful, it's faster. You can't read one byte, you can only read one word. Every decent compiler will turn booleans into words.

                        T 1 Reply Last reply
                        0
                        • J [email protected]

                          Wait until you hear about alignment

                          B This user is from outside of this forum
                          B This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #22

                          The alignment of the language and the alignment of the coder must be similar on at least one metric, or the coder suffers a penalty to develop for each degree of difference from the language's alignment. This is penalty stacks for each phase of the project.

                          So, let's say that the developer is a lawful good Rust zealot Paladin, but she's developing in Python, a language she's moderately familiar with. Since Python is neutral/good, she suffers a -1 penalty for the first phase, -2 for the second, -3 for the third, etc. This is because Rust (the Paladin's native language) is lawful, and Python is neutral (one degree of difference from lawful), so she operates at a slight disadvantage. However, they are both "good", so there's no further penalty.

                          The same penalty would occur if using C, which is lawful neutral - but the axis of order and chaos matches, and there is one degree of difference on the axis of good and evil.

                          However, if that same developer were to code in Javascript (chaotic neutral), it would be at a -3 (-6, -9...) disadvantage, due to 2 and 1 degree of difference in alignment, respectively.

                          Malbolge (chaotic evil), however, would be a -4 (-8, -12) plus an inherent -2 for poor toolchain availability.

                          ..hope this helps. have fun out there!

                          S 1 Reply Last reply
                          0
                          • V [email protected]

                            Let's store the boolean there then!!

                            A This user is from outside of this forum
                            A This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #23

                            That boolean can indicate if it's a fancy character, that way all ASCII characters are themselves but if the boolean is set it's something else. We could take the other symbol from a page of codes to fit the users language.
                            Or we could let true mean that the character is larger, allowing us to transform all of unicode to a format consisting of 8 bits parts.

                            1 Reply Last reply
                            0
                            • A [email protected]

                              It's not wasteful, it's faster. You can't read one byte, you can only read one word. Every decent compiler will turn booleans into words.

                              T This user is from outside of this forum
                              T This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #24

                              You can’t read one byte

                              lol what. You can absolutely read one byte: https://godbolt.org/z/TeTch8Yhd

                              On ARM it's ldrb (load register byte), and on RISC-V it's lb (load byte).

                              Every decent compiler will turn booleans into words.

                              No compiler I know of does this. I think you might be getting confused because they're loaded into registers which are machine-word sized. But in memory a bool is always one byte.

                              A 1 Reply Last reply
                              0
                              • E [email protected]

                                Could you provide an example?

                                T This user is from outside of this forum
                                T This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #25

                                The biggest problem is that each element doesn't have a unique memory address; iterators aren't just pointers.

                                1 Reply Last reply
                                0
                                • B [email protected]

                                  things that store it as word size for alignment purposes (most common afaik), things that pack multiple books into one byte (normally only things like bool sequences/structs), etc

                                  T This user is from outside of this forum
                                  T This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #26

                                  things that store it as word size for alignment purposes

                                  Nope. bools only need to be naturally aligned, so 1 byte.

                                  If you do

                                  struct SomeBools {
                                    bool a;
                                    bool b;
                                    bool c;
                                    bool d;
                                  };
                                  

                                  its 4 bytes.

                                  B 1 Reply Last reply
                                  0
                                  • H [email protected]

                                    How does that work?

                                    T This user is from outside of this forum
                                    T This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #27

                                    I think he's talking about if a variable only exists in registers. In which case it is the size of a register. But that's true of everything that gets put in registers. You wouldn't say uint16_t is word-sized because at some point it gets put into a word-sized register. That's dumb.

                                    1 Reply Last reply
                                    0
                                    • T [email protected]

                                      things that store it as word size for alignment purposes

                                      Nope. bools only need to be naturally aligned, so 1 byte.

                                      If you do

                                      struct SomeBools {
                                        bool a;
                                        bool b;
                                        bool c;
                                        bool d;
                                      };
                                      

                                      its 4 bytes.

                                      B This user is from outside of this forum
                                      B This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #28

                                      sure, but if you have a single bool in a stack frame it's probably going to be more than a byte. on the heap definitely more than a byte

                                      1 Reply Last reply
                                      0
                                      • T [email protected]

                                        You can’t read one byte

                                        lol what. You can absolutely read one byte: https://godbolt.org/z/TeTch8Yhd

                                        On ARM it's ldrb (load register byte), and on RISC-V it's lb (load byte).

                                        Every decent compiler will turn booleans into words.

                                        No compiler I know of does this. I think you might be getting confused because they're loaded into registers which are machine-word sized. But in memory a bool is always one byte.

                                        A This user is from outside of this forum
                                        A This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #29

                                        Sorry, but you're very confused here.

                                        1 Reply Last reply
                                        0
                                        • M [email protected]

                                          This reminds me that I actually once made a class to store bools packed in uint8 array to save bytes.

                                          Had forgotten that. I think i have to update the list of top 10 dumbest things i ever did.

                                          rikudou@lemmings.worldR This user is from outside of this forum
                                          rikudou@lemmings.worldR This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #30

                                          Ah, the creator od std::vector<bool>?

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups