this post was submitted on 14 Jan 2025
264 points (89.5% liked)

Programmer Humor

20002 readers
1380 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 27 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 day ago
gender: impl Any
[–] [email protected] 10 points 3 days ago

My gender is a null-pointer.

[–] [email protected] 43 points 4 days 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.

[–] [email protected] 14 points 4 days ago

My gender is

{ toString: ()=>{String.prototype.toString = ()=>">:3"; return ":3";} }
[–] [email protected] 6 points 3 days ago

A boolean, so 8 bits of freedom to fill up

[–] [email protected] 27 points 3 days ago (3 children)

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

[–] [email protected] 10 points 3 days ago

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

[–] [email protected] 11 points 3 days 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.

[–] [email protected] 8 points 3 days 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.

[–] [email protected] 3 points 2 days 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.

[–] [email protected] 4 points 3 days ago

Solution: 1 bit computer

[–] [email protected] 16 points 3 days ago

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.

[–] [email protected] 3 points 3 days ago

Gender is a second order tensor, so you should store it as a pointer to an array of pointers for maximum read/write speed.

[–] [email protected] 11 points 3 days ago

Gender is a pointer

[–] [email protected] 4 points 3 days ago

Gender: true

[–] [email protected] 9 points 3 days ago

Now is the time for quantum computing

[–] [email protected] 8 points 4 days ago

Why not a linked list? Or a hash-table?

[–] [email protected] 4 points 3 days ago (1 children)
[–] [email protected] 2 points 3 days ago (1 children)
import isFemale

def isMale(Person):
     if isFemale(Person):
          return False
     else:
          return True
[–] [email protected] 9 points 3 days ago (1 children)
public boolean isMale() {
    return !isFemale();
}

public boolean isFemale() {
    return !isMale();
}
          
[–] [email protected] 5 points 3 days ago

StackOverflowException was unhanded

[–] [email protected] 4 points 3 days ago (1 children)

Gender is obviously a signed byte.

[–] [email protected] 3 points 3 days ago* (last edited 3 days 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 2 points 3 days ago

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

[–] [email protected] 1 points 3 days 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?

[–] [email protected] 1 points 2 days ago

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