This is a question that essentially started after the James Bond novels and movies became popular. Ian Fleming was looking for what is now termed a signature drink for James Bond. He wanted something different from the usual , something that would reflect some exotic worldliness on the part of James Bond. For a detailed look at the drinks James Bond favored go to:
Before all that nonsense got started there were much clearer, accepted ways on which or what cocktail was shaken or stirred for a variety of reasons.
A lot of people talk about " Bruising the Gin" if shake a martini - this is not accurate.
It comes down aeration and dilution. If you shake a drink you get aeration and more dilution ( about 25% after 30 seconds) than stirring. You lose that liquid glass look and viscosity you get from a stirred drink.
One rule of thumb, if it is a clear drink (such as vodka or gin) especially straight up,stir it. It makes for a nicer presentation. That being said it does come down to personal preference... Drink what you like, made as you like that is by far the most important rule.