-14

On a number of occasions, I've come across questions and which have nothing to do with gender, but contain example code assuming binary gender. A question might ask

What's the pythonic way to designate unreachable code in python as in:

gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
    greeting = 'Mr.'
elif gender == 'f':
    greeting = 'Ms.'
else:
    # how to indicate this can't happen?

when something like this would be equally illustrative, but be uncontroversial:

accessLevel = readFromDB(...) # should be ENUM('USER', 'ADMIN')
if accessLevel == 'ADMIN':
    showDebugInfo = True
elif accessLevel == 'USER':
    showDebugInfo = False
else:
    # how to indicate this can't happen?

Is it okay to make changes like this?

In the context of the question, this change has no bearing on the meaning. It reads from a database, it has an if/elif/else chain based on the result (which is supposed to be an enum), some code runs based on the values, the else branch should never be taken.

Bringing up gender when it's not relevant, and especially claiming in example code that it can only be one of two possible values, is "likely to offend". Identity documents with three or more gender options are widely accepted and available.

Per the code of conduct:

language likely to offend or alienate people based on race, gender, sexual orientation, or religion

Many such examples literally assert that some people's genders do not exist.

I've seen previous discussions about editing old content, for example the campaign to rid Stack Overflow of bad cryptography code.

The general consensus is that if you can "fix" the answer without destroying it, do so.

If you don't see a problem with the use of gender as an example for a question that is not about gender, consider the following example in the context of a question such as "how can I ensure the value of a variable is one from a small list":

(I'm sorry that this is provocative, but it wouldn't illustrate the point otherwise)

if race not in ('white', 'black'):
    raise ValueError(f'invalid value for race: `{race}`')

This is not a duplicate.

The previous question it was marked as duplicate based on asked whether it was okay to replace "dude" with "person". While "dude" could be considered to be not inclusive, I don't think it rises to the level of "likely to offend", whereas "there are only two genders" does.

New contributor
ryanc is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
24
  • 3
    I would not fix someone else's code unless the OP specifically asked for a more gender-fluid solution, and even so, our fixes should not change the intent of the answer. Better, instead, to vote on answers according to your perception of their utility and correctness, and to create your own answer, if you feel it is needed in that particular situation. If you find something egregiously offensive, for example, a post that denigrates someone's gender, then that text should be flagged for moderator attention. Mar 16 at 20:43
  • 11
    Then that is hardly offensive since it does not directly insult or denigrate anyone. Leave it alone and post your own answer if you feel it is needed. Mar 16 at 20:48
  • 1
    @vr. FWIW, the overwhelming majority of cases are just that (or more or less that), for a large array of reasons. Mar 16 at 20:51
  • 2
    ".. a question asking about how to indicate code paths that should be unreachable." - I am confused by what your question is or how it relates to gender identity? The proposed sample code could have been any other binary decision, and the else statement in the code, would have been unreachable. So my stance, is to leave code in a question the way the author wrote it, since political and society policies, have little to do with the sample code or any question about an IFELSEIFELSE conditional statement involving a variable with a binary value. BLUF: I would reject any unnecessary edit proposal Mar 16 at 20:53
  • 1
    @SecurityHound That's exactly my point. A question about how to tag unreachable code paths has nothing to do with genders, so genders shouldn't be used as examples for them.
    – ryanc
    Mar 16 at 20:55
  • 4
    Sure genders can be used. Why conflate what is at worst an over-simplification of datasets with what you appear to be calling a terrible coding error? The example, even if wrong, can be used to illustrate a coding point. Mar 16 at 20:57
  • 6
    @ryanc - But changing an author's code, to address isn't political and society policies, serves no purpose since the code being provided typically is just a MRE Mar 16 at 20:57
  • 3
    @ryanc - I don't understand why it's relevant to answering a question about a conditional statement, laws like GDPR are political, and the other half of the spectrum is societal. If a conditional statement is performed on a binary variable, which can only be one of two values, then the else statement in an IF_ELSEIF_ELSE conditional would be a unreachable no operation code block. It confuses me what you are asking exactly. You suggest the code is bad practice but don't actually express the reason it is, putting explicit else statements, is a practice I routinely use. Mar 16 at 21:21
  • 3
    @ryanc - I neither agree or disagree regards to the topic of the existence or the concept of genders. My thoughts as a programmer are difference then my thoughts as a member of society. Mar 16 at 21:30
  • 2
    @SecurityHound Okay? But what's wrong with changing it, if the actual question had nothing to do with gender?
    – ryanc
    Mar 16 at 21:31
  • 2
    Again, never change a user's intent in their answer, and that is what is wrong with changing the answer. Again, if you feel that you have a better answer, then post a better answer. Mar 16 at 22:24
  • 5
    "Asserting (often literally) that someone's gender doesn't exist seems to obviously qualify as "likely to offend"." - but... no genders exist, in any reified, objective sense, and nobody objectively "has" a gender. That's what it means for something to be a social construct. Activists don't get to decide societal consensus. Nobody has a justifiable claim to injury from someone else not seeing the world the same way - on the contrary, persecution for thoughtcrime is the potential injury here. Mar 16 at 22:58
  • 3
    Labels like "male", "female" and (haven't the activists come up with anything yet that isn't defined purely by deduction? Is that not itself disturbing? Doesn't a gender label that can only be understood in terms of "not that", inherently center and normalize "that"?) are categorizations; applying them to the natural world doesn't change the state of the natural world. Mar 16 at 23:00
  • 6
    @ryanc - “But what's wrong with changing it, if the actual question had nothing to do with gender?” - You haven’t provided a reason to change it, other than reason associated with social normalcy or political reasons like “GDPR”, which is how I know this question is about gender equality identity not correcting sample code in a nonexistent question. With that, I am done beating around the bush, you have an agenda and I refuse to help you achieve it. Good Day! Mar 16 at 23:39
  • 10
    "I don't understand how gender is political?" You propose that there is a right and a wrong way to view a topic, and further that how the topic is viewed has implications for policies that, you argue, should or should not be adopted by governing bodies (here, the self-governing body that is the Stack Overflow Meta community), and you furthermore imply that setting policy incorrectly would be a moral failing. It's hard to imagine a more textbook example of "political". (Something doesn't stop being a matter of opinion just because of how you feel when someone disagrees with you about it.) Mar 16 at 23:47

3 Answers 3

16

Don't.

There's nothing "broken" with the question in that it's asking a reasonable technical question; their business logic must accommodate more than two genders, and they're asking for an approach on how to do it. At best this question is probably unclear or too broad since we don't know their requirements.

But there's nothing for you to edit or improve in the question. The OP would need to highlight what their own requirements are.

10
  • 14
    @ryanc: Don't presume their culture. It could be that this is an alien concept to them. You can't introduce that sort of thing in an edit.
    – Makoto
    Mar 16 at 21:10
  • @ryanc: But in doing so, you lose the intent of the question and the meaning of the question entirely. Someone asked this specific question in this specific domain for this specific purpose. There is nothing to be gained from injecting "neutral" language into this just to avoid the fact that this developer just so happens to be facing a challenge in dealing with more than two genders.
    – Makoto
    Mar 16 at 21:27
  • 7
    @ryanc: Someone asking about what to do with more than two genders is hardly problematic. Someone declaring that there are no more than two genders is very problematic. This is a situation that is clearly the former, and not the latter. Please don't make this into something bigger than it absolutely has to be.
    – Makoto
    Mar 16 at 21:31
  • 1
    @ryanc - I don’t believe that the question you cited even exists. Even if it doesn’t I don’t believe it’s been well received, because the nature of the question, is trivial in nature and likely is a duplicate of a hundred dozen different questions Mar 16 at 23:41
  • 2
    @ryanc: Okay, from that question I can safely say...you're making a much bigger deal of this than it needs. Giving the OP the benefit of the doubt, they probably didn't have to deal with more than two genders as a part of this work they were doing. Fixing it now doesn't really make it better. In fact, it introduces something to the question that...really wasn't needed to be introduced in the first place. Let this one be.
    – Makoto
    Mar 17 at 0:27
  • 1
    @ryanc - There absolutely is no reason to edit that question. Editing variable names and modifying comments, doesn’t improve the clarity or quality of the question, editing it today serves absolutely no purpose Mar 17 at 0:59
  • The question pointed out was an exemplar type question from a long time ago, surely the suggestions that there are only two genders may make StackOverflow less welcoming to those who are neither male or female as the question imply they don't exist. It doesn't hurt to change this to a more neutral example if we are going to keep this a "reasonable technical question" when the focus is literally on how to handle unreachable code path. Mar 17 at 3:43
  • 3
    @metatoaster - It's not Stack Overflow that is suggesting the number of genders that exist, it's an old question from 2009, modifying a couple of comments and a variable name WILL NOT improve the quality of that question. One would literally have to go looking for that question to be offended. Mar 17 at 5:01
  • @SecurityHound It's not about being offended, it would be useful to modify content to be less alienating for a group of people. I don't get the insistence on being hostile to the idea to modify content to be more neutral when it is possible to do so, and when there is no technical reason why the less neutral text be left in place when a less distracting, more neutral text be put into place to avoid the need to have this discussion in the first place. Mar 17 at 6:22
  • 1
    I don’t get offended by variable names. I will maintain that an edit to the code in the question would be superficial since it does make the question easier to understand. Mar 17 at 14:10
15

Don't change this code.

We should change the code or sample data if it had an obscene remark or something that would generally be considered NSFW. However, an example using two genders is a perfectly valid example of someone's actual code.

Some people disagree with the fact that there are two genders, and there are people who disagree there are more than two. Stack Overflow is not the place to start arguments about who is right. You may disagree with this part of the answer, but the question wasn't asking about how many genders there are. The question has nothing to do with genders. There's no need to start pointless arguments by editing code to fit your worldview. This applies to political statements, religious views and everything else that isn't programming-related.

If you really think that the code example is contentious, and you want to prevent someone from complaining about it in the future, you could try to edit the question and all answers with a neutral example. But we are living in 2023, so chances are that your new example could offend a new group of people. Better to just leave it alone.

Edit code only to fix programming mistakes. If the code has security vulnerabilities or really bad quality code, adjust it to improve it. Stack Overflow is all about learning to program correctly; these edits matter.

6
  • 2
    @ryanc If there are legal issues then it would be a good question for law.se or some similar site. Stack Overflow is not interested in legalities of code and this is explicitly off-topic.
    – Dharman Mod
    Mar 16 at 21:20
  • "comes across as inflammatory" It's not though. But it proves my point. Anything I say could offend someone, even this very comment.
    – Dharman Mod
    Mar 16 at 21:22
  • @ryanc - We are not lawyers. So why would I as an editor, attempt to solve a legal problem that might or might not exist within their code, for an author of a question? Your last comment raises the concern if you are actually asking about an actual question you attempted to answer? Mar 16 at 21:25
  • 11
    @ryanc It's definitely not reasonable to be offended by a denial that a gender exists. Generally, getting offended is unreasonable. But once again, this is off-topic and not something that is worth attention on this platform. As long as nobody is breaching CoC, e.g. targeting user based on their gender, cursing them out, or treating them differently in any way, then there's nothing we should do. There is a large difference between getting offended and offensive content.
    – Dharman Mod
    Mar 16 at 21:32
  • 1
    @ryanc if you were to, say, deny that men exist, or to claim that you see me as a woman, would you expect me to be anything other than amused or disinterested? Why? (What does bother me is when activists deny that biological sex exists, e.g. on the basis of the existence of intersex conditions. I might as well say that colour doesn't exist, simply because there is not an objective numeric threshold between wavelengths of light considered "red" and "orange". If anything, that one is much more plausible.) Mar 16 at 23:07
  • 1
    @Dharman I don't think it's a matter of being offended, it's more that the content is alienating a group of real people - again, to reiterate the relevant section of the code of conduct: "... language likely to offend or alienate people based on race, gender, sexual orientation, or religion." Content that outright denies the existence of a group of people - especially when the accepted answer suggests that they are invalid - by raising ValueError('invalid gender...') - is alienating. Mar 17 at 6:30
-10

When a user posts a question like the example given by OP, they are asking a question with fundamental technical flaws. A good analogy is the classic Stack Overflow post where a user asks how to parse [X]HTML with regular expressions. RegEx match open tags except XHTML self-contained tags

It seems that the guideline should follow Stack Overflow's general guidelines on answers to users who are asking how to use a tool (a boolean or enum) that is fundamentally unsuited to the job they're trying to accomplish (representing a user's gender and/or honorific)?

There are situations where programmers are forced to do this because of business requirements. But nobody is asking about their business requirements on Stack Overflow.

To be clear, I am not making any moral or political argument here. Offense is not a factor.

I am saying that if a user goes live with code like the example provided by OP, which makes an explicit assumption about a mapping between gender and honorific, they are insufficiently modeling the problem domain, and they will eventually encounter a user for which their assumption does not hold. The logic represents a software flaw in modeling the problem they're asking about. The code is incorrect.

New contributor
Sean Edwards is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 7
    I'm not quite sure what this has to do with whether or not these kinds of edits should occur. People post questions with code that is incorrect all the time, it's usually incorrect to edit them because that's precisely why it was posted, it needs to be corrected. via an answer. but your answer never really seems to... indicate any action that should or shouldn't occur?
    – Kevin B
    Mar 16 at 22:17
  • 1
    Fair point. The basis of my comment is the post above from Dharman. meta.stackoverflow.com/a/423666/53315 -- "Edit code only to fix programming mistakes. If the code has security vulnerabilities or really bad quality code, adjust it to improve it." -- I am claiming that OP's example code is a case of a programming mistake, and really bad code quality, and thus warrants an edit. Mar 16 at 22:40
  • 2
    @SeanEdwards - It’s not bad enough to merit an edit, and if you did edit the code, the only thing you should be removing is the unnecessary else statement and absolutely nothing else about the code. Whether or not gender should be represented by a binary data type is absolutely an opinion. This question absolutely nothing to do about SO or a programming question that exists on SO. Mar 16 at 23:48

Not the answer you're looking for? Browse other questions tagged .