• bastion@feddit.nl
      link
      fedilink
      arrow-up
      0
      ·
      5 days ago

      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!

  • elucubra@sopuli.xyz
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    Could a kind soul ELI5 this? Well, maybe ELI8. I did quite a bit of programming in the 90-00s as part of my job, although nowadays I’m more of a script kiddie.

    • superheitmann@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      A Boolean is a true/false value. It can only be those two values and there be represented by a single bit (1 or 0).

      In most languages a Boolean variable occupies the space of a full byte (8 bit) even though only a single of those bits is needed for representing the Boolean.

      That’s mostly because computers can’t load a bit. They can only load bytes. Your memory is a single space where each byte has a numeric address. Starting from 0 and going to whatever amount of memory you have available. This is not really true because on most operating systems each process gets a virtual memory space but its true for many microcontrollers. You can load and address each f these bytes but it will always be a byte. That’s why booleans are stored as bytes because youd have to pack them with other data on the same address other wise and that’s getting complicated.

      Talking about getting complicated, in C++ a std::vector<bool> is specialized as a bit field. Each of the values in that vector only occupy a single bit and you can get a vector of size 8 in a single byte. This becomes problematic when you want to store references or pointers to one of the elements or when you’re working with them in a loop because the elements are not of type bool but some bool-reference type.

      • Aux@feddit.uk
        link
        fedilink
        English
        arrow-up
        0
        ·
        6 days ago

        And performance optimisation of a compiler for a 64 bit CPU will realign everything and each boolean will occupy 8 bytes instead.

    • feddup@feddit.uk
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 days ago

      A boolean value only needs 1 bit (on or off) for true or false. However the smallest bit of addressable memory is a byte (8 bits) hence 7 are technically wasted.

      For low memory devices you could instead store 8 different Boolean values in one single byte by using bit masking instead

  • mavu@discuss.tchncs.de
    link
    fedilink
    arrow-up
    0
    ·
    6 days ago

    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.

    • excral@feddit.org
      link
      fedilink
      arrow-up
      0
      ·
      6 days ago

      In terms of memory usage it’s a waste. But in terms of performance you’re absolutely correct. It’s generally far more efficient to check is a word is 0 than to check if a single bit is zero.

  • ssfckdt@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    0
    ·
    7 days ago

    I swore I read that mysql dbs will store multiple bools in a row as bit maps in one byte. I can’t prove it though

  • steeznson@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    7 days ago

    We need to be able to express 0 and 1 as integers so that functionality is just being overloaded to express another concept.

    Wait until the person who made this meme finds out about how many bits are being wasted on modern CPU architectures. 7 is the minimum possible wasted bits but it would be 31 on every modern computer (even 64b machines since they default to 32b ints).

    • gamer@lemm.ee
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      7 days ago

      Consider what the disassembly would look like. There’s no fast way to do it.

      It’s also unnecessary since 8 bytes is a negligible amount in most cases. Serialization is the only real scenario where it matters. (Edit: and embedded)

      • Croquette@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        6 days ago

        In embedded, if you are to the point that you need to optimize the bools to reduce the footprint, you fucked up sizing your mcu.

    • Anders429@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      7 days ago

      It would be slower to read the value if you had to also do bitwise operations to get the value.

      But you can also define your own bitfield types to store booleans packed together if you really need to. I would much rather that than have the compiler do it automatically for me.

    • timhh@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      7 days ago

      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.

  • Treczoks@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 days ago

    This guy never coded in KEIL C on an 8051 architecture. They actually use bit addressable RAM for booleans. And if you set the compiler to pass function parameters in registers, it uses the carry flag for the first bit or bool type parameter.

  • SW42@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 days ago

    Joke’s on you, I always use 64 bit wide unsigned integers to store a 1 and compare to check for value.

  • kiri@ani.social
    link
    fedilink
    arrow-up
    0
    ·
    8 days ago

    I have a solution with a bit fields. Now your bool is 1 byte :

    struct Flags {
        bool flag0 : 1;
        bool flag1 : 1;
        bool flag2 : 1;
        bool flag3 : 1;
        bool flag4 : 1;
        bool flag5 : 1;
        bool flag6 : 1;
        bool flag7 : 1;
    };
    

    Or for example:

    struct Flags {
        bool flag0 : 1;
        bool flag1 : 1:
        int x_cord : 3;
        int y_cord : 3;
    };
    
    • lapping6596@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      8 days ago

      I watched a YouTube video where a dev was optimizing unity code to match the size of data that is sent to the cpu using structs just like this.

  • KindaABigDyl@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    8 days ago
    typedef struct {
        bool a: 1;
        bool b: 1;
        bool c: 1;
        bool d: 1;
        bool e: 1;
        bool f: 1;
        bool g: 1;
        bool h: 1;
    } __attribute__((__packed__)) not_if_you_have_enough_booleans_t;
    
    • h4x0r@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      0
      ·
      7 days ago

      This was gonna be my response to OP so I’ll offer an alternative approach instead:

      typedef enum flags_e : unsigned char {
        F_1 = (1 << 0),
        F_2 = (1 << 1),
        F_3 = (1 << 2),
        F_4 = (1 << 3),
        F_5 = (1 << 4),
        F_6 = (1 << 5),
        F_7 = (1 << 6),
        F_8 = (1 << 7),
      } Flags;
      
      int main(void) {
        Flags f = F_1 | F_3 | F_5;
        if (f & F_1 && f & F_3) {
          // do F_1 and F_3 stuff
        }
      }
      
    • xthexder@l.sw0.com
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      8 days ago

      Or just std::bitset<8> for C++. Bit fields are neat though, it can store weird stuff like a 3 bit integer, packed next to booleans

    • Gsus4@mander.xyz
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      8 days ago

      Weird how I usually learn more from the humor communities than the serious ones… 😎