>I assumed that the organization in which you work is at least partially functional and that management has an interest in ensuring good working conditions, which as you say is not always the case.
I would say this is quite rarely the case. It's amazing how many companies are able to slog through with completely braindead personnel practices. It seems most places are either far too reluctant or far too quick to terminate employees.
I know of a company that refused to fire someone who not only destroyed a production database but, on a separate occasion, accidentally facilitated an ongoing leak of the source code of all web applications (which was only discovered when it was revealed to the CEO by a script kiddie with a guilty conscience). Because this guy is well-connected, he lives to imperil the company another day (usually in slightly less dramatic ways).
I also know of a company that fires otherwise good programmers for not being at their desks by 9:05 a few times per year. Those people are terrible.
It seems that a company that is actually reasonable about its personnel practices is very rare indeed.
>If that's not possible due to resistance from management or a dysfunctional organization, you should consider leaving that position as soon as possible as it is not a good environment to work in (and as the author says, luckily there are enough opportunities for good programmers these days). But again, the problem here would not be the single bad programmer, but the setup of the whole organization, which is unfortunately much harder to fix.
You're right that often you can't fire someone for legal or political reasons, which is unfortunately all too common. However, I must oppose your proposal to just leave the org.
As discussed above, there are not many sanely-run companies out there. In my career, I used to take the "just leave" advice, but I've found this really stunts your ability to grow, personally and professionally, along multiple axes.
Unreasonable people are, unfortunately, a fact of life. I used to think a smart company could mostly avoid having them in the ranks. I still believe a smart one could more or less do this, and that damage from the stragglers can be mitigated, but I now just believe smart companies are unicorns and you should never expect to be working at one. This is a safe/important assumption because "smart companies" can turn dumb real quick, especially when/as visionary leadership is replaced by conventional business school cogs.
One must become a politician, which will enable one to flourish in the chaos, especially if passable political craft is combined with actual technical skill and good judgment.
If you're stuck with bad talent that can't be fired, you should redirect them into a side channel where the amount of damage they do is mitigated. There's actually a lot of bad employees who are perfectly OK with this. Most of them are primarily interested in security, since they know it's difficult to find new employers with their limited skillsets. Giving them their own little irrelevant kingdom will help with that and also keep the high-level bosses happy because they don't have to fire their cousin and make Thanksgiving awkward for the rest of eternity, or deal with a lawsuit from an employee who has already threatened to take the company to the cleaners.