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.
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.
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.
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.
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
}
25 Comments
steventhedev@lemmy.world · 44 pts · 1y
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.
zea_64@lemmy.blahaj.zone · 14 pts · 1y
My gender is
Artyom@lemm.ee · 6 pts · 1y
A boolean, so 8 bits of freedom to fill up
joyjoy@lemm.ee · 29 pts · 1y
Even booleans take up 8 bits. And that's a lot of wasted space.
ZILtoid1991@lemmy.world · 11 pts · 1y
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 · 9 pts · 1y
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 · 3 pts · 1y
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.
Gladaed@feddit.org · 11 pts · 1y
That's only due to technical reasons on weird platforms like x86, 64bit x86 or ARM.
__nobodynowhere@startrek.website · 4 pts · 1y
Solution: 1 bit computer
bishbosh@lemm.ee · 16 pts · 1y
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.
flamingo_pinyata@sopuli.xyz · 11 pts · 1y
Gender is a pointer
Excrubulent@slrpnk.net · 11 pts · 1y
My gender is a null-pointer.
M33@lemmy.sdf.org · 9 pts · 1y
Now is the time for quantum computing
hendrik@palaver.p3x.de · 8 pts · 1y
Why not a linked list? Or a hash-table?
vga@sopuli.xyz · 5 pts · 1y
Gender: true
spongebue@lemmy.world · 4 pts · 1y
isMale
Bumblefumble@lemm.ee · 2 pts · 1y
spongebue@lemmy.world · 9 pts · 1y
__nobodynowhere@startrek.website · 5 pts · 1y
StackOverflowException was unhanded
Abnorc@lemm.ee · 4 pts · 1y
Neptr@lemmy.blahaj.zone · 4 pts · 1y
Gender is obviously a signed byte.
ZILtoid1991@lemmy.world · 3 pts · 1y
Gender is a struct
activ8r@sh.itjust.works · 3 pts · 1y
Now this is a gender definition I can get behind. None of that string/enum crap, just raw data.
alex@programming.dev · 1 pts · 1y
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 pts · 1y
Just don't have gendered bathrooms, simple as that.
lseif@sopuli.xyz · 2 pts · 1y
fl42v@lemmy.ml · 1 pts · 1y