(Don't Call Yourself a Programmer: www.kalzumeus.com/2011/10/28/dont-call-yourself-a-programmer/)
What's amazing to me is that every company I've ever known of has a policy along those lines, yet it is illegal to sanction employees for talking about their pay with coworkers under the National Labor Relations Act and has been for a long, long time.
I also wonder to what extent the jealousy argument applies in the real world. It makes sense, and I'm sympathetic to it, but I've worked at two jobs where it was pretty well known what everyone made. There were huge disparities in what people made for doing the same work in both cases. It didn't cause any resentment issues I know of - but I suspect it did make people more likely to ask for a raise when they knew what was possible, which I think is the problem that management really has with it, because it becomes much harder for them to justify to the employee why they can't or won't pay them more, even though there may be valid reasons for it.
The invisible hand of the market will lead prople to companies with the highest value for X2, which are usually also those where the productivity (i.e. contribution to company revenue) per person is highest.
This has two effects (1) Saves me a lot of time on the negotiation front. If the announcement doesn't pay what you want, don't apply to it. Saves me and the hiring manager a lot of wasted time if I were to apply to a post thinking I'll get paid $X when it will really pay $Y. And (2) Since it's all public anyway, everyone knows that if you want to make $X then you need to train into position Y and you have a pretty concrete list of knowledge/skills that you can hack away on to achieve that. None of this blind guess work.
[I have no explanation for why she stayed there for 9 years]
Their salaries gave me the incentive to demand a big raise from my employer. Which I did and didn't get, so I quit and got myself a much better paid job.
These policies are actually often illegal due to the National Labor Relations Act.
So if you tell someone your salary, your job probably feels more difficult to you than it looks to them, and you probably feel more productive than they think you are. If you make the same or more than they do, there is a very high risk that they will think you are overpaid.
This is obviously a risk to the company, which is why most companies (at least in the US) have a policy against it. But it is also a risk to you and your relationship with that other person, which is why few people share their salary information with their friends.
You are right that this is a fundamental problem for equality. But it is not an easy or safe thing to change, which means it will take a lot of time and effort.
I am not saying that the status quo should remain. I'm just pointing out the reason it is difficult to change.