Normally, the dictum is to befriend civs far away and attack close-by neighbors. But because of stability issues, this needs to be modified to a technique that basically weaken civs which are in another part of the world without much cost to you, and I prefer no war that I initiate at least until after Assembly Line.
This is invaluable in keeping traditionally advanced or powerful civs a little behind. Say you're Japan, and you have good relations with almost everybody after selling them your map. You're isolated, and nobody's going to be able to attack you successfully. Your defensive pacts should be made with either Russia/Turkey/France and you should war against Germany and Mongolia, or with Mongolia/Spain/Germany and declare on France/Russia. If you have AI tech leader that is small (France), you should befriend Spain and Germany and hope they declare on each other. England is a bad ally because they are so isolated on their islands, while the Dutch are useless because they can be taken out so easily.
What if you're France (lots of close contacts)? You want to befriend the Vikings Germany and Spain, but declare on Russia/Turkey (so that Germany will take the brunt of their army). In the far east your ally should either be Mongolia or China, depending on who's stronger, so that Russia can be heckled on both sides.
What if you're Turkey/Arabia/Persia, Germany or Russia with lots of enemies around? You have to get at least one of your big neighbors to be your friend so that when the inevitable attack comes from the 3rd party, you won't need to defend yourself as much. This is especially true of Germany which has so many fronts to defend; France for that reason I always befriend so that my troops can stay on the Russian/Turkish side.
What if you're a small civ like Portugal and Netherlands? Of course you want all your neighbors to be happy, and you may not even want to sign any defensive pacts unless you're able to defend yourself against your large neighbor (Spain and Germany).