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

断了今生、忘了曾经 提交于 2019-12-06 07:44:55

问题


[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.


回答1:


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



回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/8005681/what-is-the-convention-to-use-boolean-for-gender-in-programming-languages-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!