1116
Tell me the truth ... (piefed.jeena.net)
top 50 comments
sorted by: hot top controversial new old
[-] jenesaisquoi@feddit.org 11 points 2 days ago

Wait until you hear about alignment

[-] bastion@feddit.nl 2 points 1 day 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!

[-] mavu@discuss.tchncs.de 13 points 2 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.

[-] houseofleft@slrpnk.net 8 points 2 days ago

Wait till you here about every ascii letter. . .

[-] answersplease77@lemmy.world 4 points 2 days ago
[-] Iron_Lynx@lemmy.world 5 points 2 days ago* (last edited 3 hours ago)

ASCII was originally a 7-bit standard. If you type in ASCII on an 8-bit system, every leading bit is always 0.

(Edited to specify context)

At least ASCII is forward compatible with UTF-8

[-] Jankatarch@lemmy.world 1 points 1 day ago

Is ascii base-7 fandom's strongest argument...

[-] houseofleft@slrpnk.net 3 points 2 days ago

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

[-] Valmond@lemmy.world 10 points 2 days ago

Let's store the boolean there then!!

[-] acockworkorange@mander.xyz 37 points 3 days ago

In the industrial automation world and most of the IT industry, data is aligned to the nearest word. Depending on architecture, that's usually either 16, 32, or 64 bits. And that's the space a single Boolean takes.

[-] ZILtoid1991@lemmy.world 18 points 3 days ago

That's why I primarily use booleans in return parameters, beyond that I'll try to use bitfields. My game engine's tilemap format uses a 32 bit struct, with 16 bit selecting the tile, 12 bit selecting the palette, and 4 bit used for various bitflags (horizontal and vertical mirroring, X-Y axis invert, and priority bit).

[-] acockworkorange@mander.xyz 27 points 3 days ago

Bit fields are a necessity in low level networking too.

They're incredibly useful, I wish more people made use of them.

I remember I interned at a startup programming microcontrollers once and created a few bitfields to deal with something. Then the lead engineer went ahead and changed them to masked ints. Because. The most aggravating thing is that an int size isn't consistent across platforms, so if they were ever to change platforms to a different word length, they'd be fucked as their code was full of platform specific shenanigans like that.

/rant

load more comments (3 replies)
[-] KindaABigDyl@programming.dev 173 points 3 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;
[-] xthexder@l.sw0.com 40 points 3 days ago* (last edited 3 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

load more comments (1 replies)
load more comments (3 replies)
[-] skisnow@lemmy.ca 52 points 3 days ago

Back in the day when it mattered, we did it like

#define BV00		(1 <<  0)
#define BV01		(1 <<  1)
#define BV02		(1 <<  2)
#define BV03		(1 <<  3)
...etc

#define IS_SET(flag, bit)	((flag) & (bit))
#define SET_BIT(var, bit)	((var) |= (bit))
#define REMOVE_BIT(var, bit)	((var) &= ~(bit))
#define TOGGLE_BIT(var, bit)	((var) ^= (bit))

....then...
#define MY_FIRST_BOOLEAN BV00
SET_BIT(myFlags, MY_FIRST_BOOLEAN)

load more comments (6 replies)
[-] midori_matcha@lemmy.world 18 points 2 days ago
[-] camelbeard@lemmy.world 7 points 2 days ago

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

load more comments (1 replies)
[-] ricecake@sh.itjust.works 132 points 3 days ago

I set all 8 bits to 1 because I want it to be really true.

[-] laranis@lemmy.zip 92 points 3 days ago* (last edited 3 days ago)

01111111 = true

11111111 = negative true = false

[-] Jankatarch@lemmy.world 2 points 1 day ago

negative true = negative non-zero = non-zero = true.

[-] StellarSt0rm@lemmy.world 47 points 3 days ago
[-] Venator@lemmy.nz 1 points 1 day ago

Is this quantum computing? 😜

load more comments (5 replies)
load more comments (10 replies)
load more comments (4 replies)
[-] Lucien@mander.xyz 133 points 3 days ago
[-] mmddmm@lemm.ee 150 points 3 days ago

And compiler. And hardware architecture. And optimization flags.

As usual, it's some developer that knows little enough to think the walls they see around enclose the entire world.

load more comments (6 replies)
[-] elucubra@sopuli.xyz 4 points 2 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 8 points 2 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 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.

[-] WanderingThoughts@europe.pub 94 points 3 days ago

string boolEnable = "True";

[-] 30p87@feddit.org 87 points 3 days ago

Then you need to ask yourself: Performance or memory efficiency? Is it worth the extra cycles and instructions to put 8 bools in one byte and & 0x bitmask the relevant one?

load more comments (10 replies)
[-] catnip@lemmy.zip 53 points 3 days ago

Wait till you find out about alignment and padding

[-] JiminaMann@lemmy.world 2 points 1 day ago

Tell me the truth, i can handle it

[-] Jankatarch@lemmy.world 5 points 2 days ago* (last edited 2 days ago)

I mean is it really a waste? What's minimum amount of bits most CPUs read in one cycle.

[-] excral@feddit.org 10 points 2 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.

[-] savedbythezsh@sh.itjust.works 13 points 2 days ago

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

[-] Anders429@programming.dev 32 points 2 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 23 points 2 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.

[-] ethancedwards8@programming.dev 7 points 2 days ago

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

load more comments (2 replies)
[-] Jankatarch@lemmy.world 4 points 2 days ago

CPUs don't read one bit a a time.

load more comments (2 replies)
[-] Subverb@lemmy.world 38 points 3 days ago* (last edited 3 days ago)

The 8-bit Intel 8051 family provides a dedicated bit-addressable memory space (addresses 20h-2Fh in internal RAM), giving 128 directly addressable bits. Used them for years. I'd imagine many microcontrollers have bit-width variables.

bit myFlag = 0;

Or even return from a function:

bit isValidInput(unsigned char input) { // Returns true (1) if input is valid, false (0) otherwise return (input >= '0' && input <= '9'); }

load more comments (7 replies)
[-] JakenVeina@lemm.ee 28 points 3 days ago

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 (1 replies)
[-] glitchdx@lemmy.world 26 points 3 days ago

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 3 days ago

It's 7 bits....

Pay attention. 🤪

[-] JasonDJ@lemmy.zip 29 points 3 days ago

7 bytes! Look at Mr. Moneybags here!

load more comments (1 replies)
load more comments
view more: next ›
this post was submitted on 15 May 2025
1116 points (100.0% liked)

Programmer Humor

23326 readers
350 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