What is the convention to use boolean for gender in programming languages? true male false female? [closed]

StackOverflow https://stackoverflow.com/questions/8005681

  •  21-02-2021
  •  | 
  •  

Question

[Edit] Sorry I mean no offence to women, this question troubled me several times. I just like to know a conventional or universal way (in both database and... other programming languages). Thank you.

Is there a conventional way to show gender using boolean?

Are they the same in all languages? JAVA, C, Objc, databases?

I guess we should use true (1) for male and false (0) for female?

Thank you.

Was it helpful?

Solution

true (1) for male and false (0) for female

OTHER TIPS

If you want to use a boolean it might be a good idea to call your variable either isMale or isFemale rather than just gender to make it clear what the value true means.

However in many countries it is not legal to require people to disclose their gender if they don't wish to, so you may have to use an enum with three values:

Female
Male
Unknown

What's wrong with a single character, containing one from the set {'m','f','n'} for male, female and not applicable?

I'm sure you're not that hard up for space that you need to pack all your genders into bitmaps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top