this post was submitted on 15 May 2025
1148 points (98.6% liked)

Programmer Humor

23417 readers
1648 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
(page 2) 50 comments
sorted by: hot top controversial new old
[โ€“] borokov@lemmy.world 34 points 1 week ago (1 children)
[โ€“] Gsus4@mander.xyz 11 points 1 week ago* (last edited 1 week ago)

Weird how I usually learn more from the humor communities than the serious ones... ๐Ÿ˜Ž

[โ€“] pelya@lemmy.world 32 points 1 week ago (2 children)

std::vector<bool> fits eight booleans into one byte.

std::vector<std::vector> is how I stored the representation of a play field for a Tetris game I made once.

load more comments (1 replies)
[โ€“] JakenVeina@lemm.ee 26 points 1 week ago (11 children)

It's far more often stored in a word, so 32-64 bytes, depending on the target architecture. At least in most languages.

load more comments (11 replies)
[โ€“] glitchdx@lemmy.world 23 points 1 week ago (1 children)

if wasting a byte or seven matters to you, then then you need to be working in a lower level language.

[โ€“] MystikIncarnate@lemmy.ca 27 points 1 week ago (1 children)

It's 7 bits....

Pay attention. ๐Ÿคช

[โ€“] JasonDJ@lemmy.zip 30 points 1 week ago (1 children)

7 bytes! Look at Mr. Moneybags here!

[โ€“] Hupf@feddit.org 10 points 1 week ago

Well when it comes to bytes, you could say I'm a bit of a millionaire myself.

[โ€“] SW42@lemmy.world 22 points 1 week ago (1 children)

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

[โ€“] aport@programming.dev 9 points 1 week ago

So does the cpu

[โ€“] kiri@ani.social 21 points 1 week ago* (last edited 1 week ago) (1 children)

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;
};
load more comments (1 replies)
[โ€“] midori_matcha@lemmy.world 21 points 1 week ago (1 children)
[โ€“] camelbeard@lemmy.world 8 points 1 week ago (2 children)

I first thought you wrote boolean float, not sure if that's even worse.

load more comments (2 replies)
[โ€“] JasonDJ@lemmy.zip 17 points 1 week ago (1 children)
load more comments (1 replies)
[โ€“] Skullgrid@lemmy.world 16 points 1 week ago (1 children)

just like electronic components, they sell the gates by the chip with multiple gates in them because it's cheaper

load more comments (1 replies)
[โ€“] savedbythezsh@sh.itjust.works 14 points 1 week ago (6 children)

Are you telling me that no compiler optimizes this? Why?

[โ€“] Anders429@programming.dev 34 points 1 week 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 23 points 1 week ago (4 children)

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.

load more comments (4 replies)
load more comments (4 replies)
[โ€“] jenesaisquoi@feddit.org 13 points 1 week ago (1 children)

Wait until you hear about alignment

load more comments (1 replies)
[โ€“] mavu@discuss.tchncs.de 12 points 1 week 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.

[โ€“] houseofleft@slrpnk.net 9 points 1 week ago (6 children)

Wait till you here about every ascii letter. . .

load more comments (6 replies)
[โ€“] steeznson@lemmy.world 8 points 1 week 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).

load more comments
view more: โ€น prev next โ€บ