The first thing to remember is that when you are stopped, the officer is in charge. There is no argument, debate, or law on the books that will tell you otherwise. Listen to his instructions, even if you hate cops, if you think this guy is a dick, or whatever.
Stop in a safe area, usually on the right shoulder, but you may get some leeway from an officer if you go a few hundred yards extra to pull into a gas station or motel or somesuch.
Shut down your vehicle, ignition off, and engage hazard warning lights. (Turn off headlights to save your battery.)
Now... we have an officer about to approach a vehicle for something as simple as an infraction, but in his mind it might just be a violent felon that was just described over the radio that he is about to engage. Make the officer feel safe. Again, make the officer feel safe, so that he doesn't plug you with a round.
Keep your hands on the wheel, and instruct any passengers to stay still. When the officer approaches you may have to make movements to lower your window in order to speak with the officer clearly, but wait until you are instructed to do so.
The same goes for showing your papers. Your license, registration, insurance card... only present them when instructed to to so, and do so calmly, as instructed.
At that point the officer has probably already decided to ticket you or not. Sob stories, "I know the Chief" and all that crap are not gonna do you much good. Keep your hands visible and follow any instruction the officer gives. He is in full tactical mode, and will shoot you without thinking twice about it.
I have been through many traffic stops, even felony stops (that weren't really felonies, at least on my part, after all) and in each one the adrenaline runs high for both parties. Stay calm, breathe, and listen to instructions. At the end of the day, whether you like it or not, whether you agree with the ticket or not, the cop is in charge with no doubt. If you think he is wrong, if you think he's a dookie stain, take it up with the judge and/or file a complaint. DO NOT ARGUE WITH THE COP. If you think you have been wronged, tell the judge, and/or call a lawyer. You are not going to win here, or change the cop's mind with some Jedi mind tricks. Live to fight another day.