this post was submitted on 14 Jan 2025
28 points (86.8% liked)

Programmer Humor

27516 readers
544 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
 
all 21 comments
sorted by: hot top controversial new old
[–] Excrubulent@slrpnk.net 4 points 10 months ago

My gender is a null-pointer.

[–] joyjoy@lemm.ee 4 points 10 months ago (2 children)

Even booleans take up 8 bits. And that's a lot of wasted space.

[–] Gladaed@feddit.org 3 points 10 months ago

That's only due to technical reasons on weird platforms like x86, 64bit x86 or ARM.

[–] ZILtoid1991@lemmy.world 2 points 10 months ago (1 children)

That's why you use bitarrays and bitflags instead when you need more than just one or two arguments for a function.

[–] Excrubulent@slrpnk.net 4 points 10 months ago (1 children)

Only if it's performance sensitive. Otherwise you're wasting programmer time both writing and reading the code, and you've made it less maintainable with more complexities where bugs can creep in.

The vast majority of the time you can afford a few wasted bits.

Honestly though I don't quite understand why a compiler couldn't optimise this process. Like it knows what a boolean is, surely it could reduce them down to bits.

[–] calcopiritus@lemmy.world 1 points 10 months ago

Well, to get a boolean out of a bit array you have to do some operations. So at first it doesn't make it more performant. Compilers probably don't automatically make them bitarrays because of that.

However, the memory savings means less cache used. And a cache miss is way more expensive than those bit operations. So they should be more performant. I'm sure someone out there has done the actual research and there's a good reason why compilers don't make all booleans bitarrays.

[–] steventhedev@lemmy.world 3 points 10 months ago (2 children)

Clearly your gender field is a boolean. Which means it can be either true, false, null, or undefined. Except in javascript where for some reason it can sometimes be NaN, but only when you try to compare two people.

[–] Artyom@lemm.ee 2 points 10 months ago

A boolean, so 8 bits of freedom to fill up

[–] zea_64@lemmy.blahaj.zone 1 points 10 months ago

My gender is

{ toString: ()=>{String.prototype.toString = ()=>">:3"; return ":3";} }
[–] vga@sopuli.xyz 2 points 10 months ago

Gender: true

[–] lseif@sopuli.xyz 2 points 10 months ago
gender: impl Any
[–] bishbosh@lemm.ee 0 points 10 months ago (1 children)

Bold of programmers to assume gender can be expressed accurately in a finite discrete system. Gonna have to bust the Taylor series for some better approximation.

[–] apotheotic@beehaw.org 0 points 10 months ago (1 children)

I guess in theory as there will only ever be a finite number of individuals, there will also necessarily only ever be a finite number of different gender expressions, so finite discrete probably works. (Not to say that peoples experiences of gender are fixed and equidistant, but more so that you could have a "gender enum" with an entry for each individual)

Of course, trying to say how many bits this would require is almost impossible because theres always going to be more people and more genders, but it is technically finite.

In any case, bagsies on (leading zeros)100101001

[–] QuazarOmega@lemy.lol 1 points 10 months ago (1 children)

Me on my way to define everyone's gender:

enum Gender {
  AARON,
  ALEX,
  ANN,
  ...
[–] I_am_10_squirrels@beehaw.org 1 points 10 months ago

I will always read it as ay-ay-ron

[–] Neptr@lemmy.blahaj.zone 0 points 10 months ago (1 children)

Gender is obviously a signed byte.

[–] ZILtoid1991@lemmy.world 0 points 10 months ago* (last edited 10 months ago) (2 children)

Gender is a struct

struct Gender {
  byte binaryBias;    ///Determines male (+) or female (-) bias if present
  ubyte binaryAm;    ///Determines the amount of binary gender(s) present
  bool isTrans;    ///True if assigned at birth gender does not equal with current one
  ubyte xenoAm;    ///Determines the amount of xenogender
  uint xenoGen;    ///Xenogender selection, 0 if not applicable
  Sex* sex;    ///Pointer to the person's current sex
}
[–] activ8r@sh.itjust.works 1 points 10 months ago

Now this is a gender definition I can get behind. None of that string/enum crap, just raw data.

[–] alex@programming.dev 0 points 10 months ago (1 children)

That's a lot of implementation detail. Is there just a service interface I can inject to know what bathroom a person's RFID fob should open?

[–] ZILtoid1991@lemmy.world 1 points 10 months ago

Just don't have gendered bathrooms, simple as that.