In real life things are even more complex: in case of a bitter divorce an employer will have some trouble trying to convince a judge that they fired a programmer because he didn't like classical music. And then programmer's attorney will present his version of events with some racial twist added...
First of all, if you sue (and you can for a number of reasons), that means litigation, even if frivolous. Secondly, most orgs don't like giving person(s) the power to fire for no reason (politics / abuse potential). Finally, unemployment insurance is a big cost; if you get "fired for cause" their rates don't go up (this systems a joke, but that's a story for another day)
So, contrary to what you might think, and people will claim on the internet, it can practically be quite hard to fire someone. You just can't sue because you got fired fired for no reason, just for other stuff (eg. discrimination)