8

I remember that in our first programming class with Java, while explaining data types, the following occurred (kinda):

Professor: So, what data type would you choose if your program needs to store the user's gender?

Someone: How about a boolean? You know, true for male and false for female.

Professor: Sure, that may work, but some people may hesitate about that. There have been disputes about calling men "true" and women "false" in the past...

*laughter *

He ended up recommending us to consider chars (like 'm' and 'f') although booleans should be fine.

I tried searching a bit if there has been any kind of historical entry regarding a major dispute based on this programming practice with no luck.

I'm not asking what data type to use for gender nor if it is fine or not to use booleans. I'm asking if, historically, there has been a dispute regarding the usage of booleans to determine the gender in programming because of the apparently "wrong" (I'm not saying it is wrong - I don't care about that) behavior of calling a woman "false" as the professor seemed to suggest.

Searching around related questions, the results happen to be only about software efficiency.

17
  • 3
    As written, that looks more like a pun than a serious description of historical programming conflicts... Feb 14, 2013 at 1:10
  • 8
    One problem with using a boolean instead of some kind of enum for modeling real world phenomena - one might want to model transgender, XXY chromosomes, etc. I have seen transgender (2 types) in a real world database as a permissible gender value. I don't know if it was the result of a dispute.
    – psr
    Feb 14, 2013 at 1:18
  • 8
    @PhillipBurch: you can still use a boolean. Just use "FileNotFound" for the third gender. Feb 14, 2013 at 1:44
  • 2
    @YannisRizos: I find it unpleasant that, as a man, you would close a question that matters a lot to people who don't identify as either male or female, and that could matter to women as well, just because you don't care about it. Especially as it has been upvoted. Feb 14, 2013 at 8:59
  • 3
    @Niphra If you disagree with the closure, feel free to post a question about it on our Meta site.
    – yannis
    Feb 14, 2013 at 9:04

3 Answers 3

5

This is more a cultural issue then technical, and represents a society's perspective on gender.

If you studied in an Islamic country or China, then I can understand why this would be an issue.

So the answer is no, I've never heard of such a silly issue in programming.

1
  • 1
    To add weight, I work with data from the NHS in England, this is national data covering the whole population. Gender is stored as an int, 1 for male or 2 for female which would raise the same sudo-ethical questions. Here an int is used over a Boolean because other values are used (e.g. unknown, transgender, etc.) but there's no hesitation about using a coding system where it improves efficiency. You wouldn't hesitate about coding other values, so why hesitate here?
    – Matt
    Feb 14, 2013 at 10:06
23

Never use a boolean just because there are only two values. Unless the meaning of true and false will be obvious, use an enumeration if available, and string constants or symbols or whatever if not. And all too often, there are initially two values and then later there are three. Or four.

4
  • 1
    Very good advice, thank you, but doesn't address the question.
    – Saturn
    Feb 14, 2013 at 2:01
  • 1
    Which is are there historical facts about a dispute when using booleans for gender due to the apparently "wrong" moral behavior of calling a woman "false"? (I realize that the title doesn't include the moral part, but the contents of the question do focus on it)
    – Saturn
    Feb 14, 2013 at 2:09
  • 1
    There are actually been disputes when using booleans due to the fact people who don't identify as female or male felt ignored or rejected - they were forced to choose a gender (see google+). The use of true/false is less of an issue. Feb 14, 2013 at 8:46
  • Considering that most programming languages use a full word to store a boolean anyway, and "gender" is decidedly not a true/false property (semantically), then you're absolutely right. Having a "false" gender isn't a social thing at all, it's just semantically incorrect and you're not even gaining a performance advantage. Feb 14, 2013 at 15:11
-4

Besides the reason given by Kevinn, using boolean in this case forces using variable and property names like isMale (or isFemale), instead of gender.

To me, a neutral name like "gender" is much better than "isblabla" as a property name.

Not the answer you're looking for? Browse other questions tagged or ask your own question.