Of course, it's absurd to suggest companies make sure every worker isn't high on the job every single day, but that doesn't change the fact that it's judging someone based on something which could have absolutely no bearing on their work.
But programmers? If Google drug tests people I'm sure they do so for liability reasons, not because they care what Johnny Genius does in his free time.
They're not allowed to discriminate based on these things, but it doesn't mean they can't know them (though obviously they probably won't ask you as that's asking for trouble).
You can't discriminate based on age or gender in the UK (amongst many other things). But if they interview you (face to face at least), I think they'd probably have a fairly good idea of those, without asking you (or looking at your facebook profile).