Most of these policies are illegal, though this isn't widely recognized
Here's why:
There are some added complexities here that Matthew's answer hasn't addressed, especially in the meanings of words like group and disadvantage. Let’s focus on the latter of the two and proceed by way of example.
Suppose the evidence suggests that the members of a particular group are under-represented in a particular discipline. But suppose the evidence also suggests that they are being actively discriminated in favour of in that same discipline. The question arises: are the members of this group at an advantage (because they're discriminated in favour of), or at a disadvantage (because they're under-performing)? This seems to be the case for women in science, for example.
Ergo, since the language is vague, it's thus an unfortunate fact of life that the legality of such things mostly depends on the politics and broader zeitgeist within which the case is heard. Left-leaning judges will tend to decide that the members of the group under question are at an overall disadvantage, despite discrimination working in their favour, and will thus tend to hold that such discrimination is lawful, while anti-left judges will tend to decide that the members of the group under question are at an overall advantage and thus that further discrimination in their favour is unlawful.
Based on the above comments, discrimination in favour of such groups will tend to be regarded as lawful in the current intellectual climate. But in my opinion, common sense dictates that the left-leaning definition of disadvantage upon which such decisions are based doesn't really stand up to scrutiny, and as time goes on and society cycles through different worldviews, I think that a consensus will eventually emerge that the anti-left conception of disadvantage makes by far the most sense. Therefore, I consider it likely that the judicial system will ultimately begin to rule that such affirmative action policies are illegal. Indeed, I think judges will eventually declare that these kinds of policies were always illegal, but that this simply wasn't recognised at the time for political reasons.
Reply to comments.
... your link discusses hiring preferences in favor of women while not addressing the question of performance, yet your comment implies that it demonstrates both.
Yes, that was poorly worded. I've fixed the issue.
Further, the study only looks at preferences of hiring faculty, while acknowledging that a bigger problem is a lack of applicants, despite a large pool of eligible applicants.
The broader question here is whether 'lack of applicants' is a form of disadvantage that can be used to justify the lawfulness of discriminatory practices. My point is really that we can't answer this from the legislation alone and are thereby forced to rely on the kinds of precedents discussed in Matthew's answer. But realistically, these precedents don't make much sense with respect to common sense notions of disadvantage, and thus are likely to change in the future. I don't necessarily mean that right-leaning judges will swoop in and totally override the precedents. Another possibility, for example, is that a general sense of disenchantment with partisan thinking will infiltrate top-tier courts; if this happens, common sense points of view will stand a better chance of becoming precedents.
You’re side-stepping the point of women being discriminated against by saying there is a hiring bias in favor of them (and that only for academic jobs). This bias doesn’t mean they are at an advantage in life generally and therefore doesn’t mean these coding classes are unjustified.
I agree to an extent, but I also think these comments are of limited relevance, and they even support my contention to some extent. If the words 'advantage' and 'disadvantage' are used without explanation of whether general life-advantage is being meant, as distinct from hiring bias, then this really politicizes the issue, because the meaning of the legislation isn't clear. Beyond this, there's really no scientific consensus on whether women in the UK are at an overall life-disadvantage or not, so your argument doesn't (currently) hold much water. Going further, I'd make the claim that given
(a) explicit bias in favor of women due to affirmative action programs that try to lower the bar somewhat for women, and
(b) implicit bias in favor of women due to a desire to correct perceived or actual discrepancies, and
(c) the fact that women have overall greater bargaining power in the domains of romance, marriage and sexuality, and
(d) the still-widespread expectation that (straight) men ought to financially support their significant others,
it seems quite likely that an overall male disadvantage will eventually be settled upon by the scientific community. Let's call this Outcome 1. A contrary possibility is that by factoring in e.g. partner-violence, etc., the establishment will arrive at the opposite conclusion. Let's call this Outcome 2. Yet another possibility is that the scientific establishment will eventually decide that there's no apolitical way to weigh up the costs and benefits of belonging to the genders under question. Let's call this Outcome 3.
Notice that if either Outcomes 1 or 3 transpire, courts higher up in the judicial hierarchy will eventually start deciding that many of these broader life-advantage arguments don't carry much weight anymore, especially if the broader spirit-of-the-times changes.
Also, I should clarify my position a bit more. My opinion is specifically that it will eventually be recognized that most of these policies were illegal all long. But I'm not saying that such policies should be illegal. Indeed, ethically, I'd say that investing in your employees should probably be OK, even if you're investing in them in very discriminatory patterns! But that's a different conversation altogether.
You say the policies are illegal, yet you provided no evidence to support this.
I respectfully disagree. As I've said, antidiscrimination law depends very heavily on the concept of disadvantage. This means scientific evidence can carry legal weight, and I've provided some. I can provide a lot more science if people request it. However, I'd much prefer people go off and research the topic themselves, since this is the best way to get a balanced picture of the literature.
The definition of "illegal" you're using is perhaps closer to "unethical". If the law supports something, it's by definition impossible for that to be illegal (legal nuance aside). Laws changing wouldn't retrospectively make things illegal.
I'm definitely talking about legality, and by the way, a change in precedent could definitely retrospectively make things illegal.
However, I'd like to concede that you make at least one strong point here, at least implicitly. Namely, notice that there's a broader question of jurisprudence lurking beneath the surface here, namely: can so-called judge-made-law really be considered law per se, as opposed to "mere" precedent? I'm pretty sure the philosophers have yet to agree on this issue, so I concede that the way my answer is written, which proceeds 'as if' the mere-precedent side had won the debate, weakens the writing somewhat. But I also think the thrust of what I'm saying is spot on. So at some level, your point here is a good one.
The last paragraph is pure speculation about the future. This has no place on Stack Exchange. The second to last paragraph is based on wishful thinking, not actual case law. This answer has no objective merit. So I believe the people who upvote this answer do so to react to a political stance they agree with.
I'll do my best to respond respectfully to this.
As you may have noticed, my answer adds nuance to Matthew's by explaining how questions pertaining to the legality of discrimination often hinge sensitively on the meaning of the word 'disadvantage', as well as on the details of the relevant science. This gives context to the current state of affairs, and unambiguously constitutes an important contribution to the broader project of answer the OP's question. This alone makes the claim of 'no-merit' come off as... well, without merit!
Beyond this, you're right that there's a degree of speculation in the latter parts of my answer. However, that's because the law is not clear-cut in this area, and therefore we cannot know whether such policies are ultimately going to be regarded as having been legal (at the time they existed) without speculating somewhat on what the future holds. That's just the situation we're in right now! I'd hardly call that pure speculation, and I think the tone you've chosen to use (characterized by e.g. strong words and phrase and choppy sentences) probably overstates the strength of your points.
I've run out of steam at this point, so I'll probably just leave it there. Apologies to the people whose comments didn't receive proper responses.