Interesting post by Scott Berkun : How to deal with jerk programmers which isn't exactly consistent with my experiences from both sides of the fence.
The best place to start is empathy. Why is someone acting like a jerk? There are basic psychological reasons for this: Either they are insecure, they are unhappy, or they are angry about something.
Ok, there is a fourth reason, that they are psychopathic hell spawn put on the earth to torture all living things in a 10 foot radius, especially you, but lets assume that’s not the case for a moment.
That fourth one sounds eerily like me, but I shall pretend thats not the case. Scott further goes on to make a set of suggestions (read his post for details, I am just listing them below)
Charm to Connect
Demonstrate your ability to help
Agree on the roles you both play
Get help from allies
While definitely in the right direction, these are very tactical steps. And I really am not sure that the jerk programmers can be "unjerked" with these. There are two types of jerk programmers. Those who simply enter the office with a combined sense of arrogance and disdain that the situation is likely to be beyond any reasonable likelihood of any decently workable relationship. Thankfully this is likely to be a very rare set (I suspect they exist, but haven't ever worked with one). At least half of the remainder are likely to have some issue with the "big picture" work atmosphere. Something that reeeallly bothers them. Something they are finding difficult to reconcile to. Something thats gnawing at them.
I think there are two options in this case. If you can largely agree with the issues, ensure that you not only empathise and help (as Scott mentions) but also make sure you're clearly seen to be believing and acting towards solving the issues. I think that belief is a very important element which sets up a shared goal and is complemented by the actions and results. The programmer needs to believe you are on the same side (in his opinions the right side) of the issues as him many times even if not completely so. This could be related to number of aspects - technology choices, code or design quality, deadline tradeoffs, deadlines, territorial control issues etc. etc. A programmer is very unlikely to actually promote himself to jerkdom because of the coffee vending machine being located on the wrong side of the aisle or even due to more serious matters such as role ambiguity or disagreement. It usually runs much deeper.
In case you cannot agree with the issues, I think a clear talk needs to be had about the differences, the criteria that are going to be laid down, and the programmer should be encouraged to either adjust to these or attempts should be made to find a role / position where such differences can be minimised. In extreme cases it may be helpful to encourage the programmer to relocate to other teams for a win-win resolution.
To summarise, if a programmer is acting like a jerk, there's likely to be a much deeper issue. Work with him, be seen to be friendly to and believing in his case and be seen to be on his side many times on the issue and demonstrate at least some tangible progress on the issue at regular intervals. Alternatively in extreme cases find avenues to work independently. There is a risk of lesser tactical resolutions simply prolonging the difficulties for all concerned.