How do you know what gun to buy? Great question. You could ask Uncle Bubba, the dude at the gun shop counter, or the guy down the street who plinks beer cans on the weekend.
The right way, however, is to try to glean the opinions of respected national level trainers (such as Todd Green, Larry Vickers, Ken Hackathorn, etc.) who get to see high volume shooting through a lot of different guns. These people work with federal law enforcement agencies, defense contractors, SWAT teams, etc, and get to see and hear first hand what works and what does not. Some of these individuals are familiar with the results of large scale law enforcement trials as well.
Additionally, look at what law enforcement agencies that procure their guns through competitive trials use. You will see mostly Glocks, M&P's, Sigs, and H&K's. That is called a clue.
The consensus right now seems to be that your best bets are the M&P, 9mm Glocks, and the H&K P30/HK45 series. These guns typically survive high round count classes and have done very well in competitive law enforcement trials. I personally prefer the M&P series (which greatly benefits from a drop-in Apex trigger set) as being the best for the money. I find Glocks to be a bit less shootable than the M&P (more recoil, longer for the sights to fall back to zero) and I have a more difficult time getting a good grip quickly. That said, the Glock is still a great shooter and if it fits your hand well it is a great choice. H&K's are expensive. Sig's quality control is currently in the toilet, but lightly used older Sigs are great too.
1911's are great shooters, but are complex guns with very tight tolerances. They need a lot of maintenance to stay reliable (if you actually train with it regularly), and unless you are an enthusiast who is competent at doing a lot of repair and refitting yourself you would probably be better served elsewhere.
For more detailed information check out m4carbine.net, lightfighter.net, and tacticalforums.com.
I strongly urge people to stay away from .40. Although it was not the case 20 years ago, the performance gap between 9mm and .40 with the best defensive ammo in 2010 is pretty much limited to shooting through boundaries such as laminated glass and car doors. My control, split times, gun wear, and wallet all suffer badly with the .40. The benefits simply do not outweigh the costs. Come to think of it, there is little difference these days between the major service calibers (unless you are shooting through boundaries). Ideas like 'energy transfer' and 'hydrostatic shock' are old wives tails. There are only two variables with handgun bullets, because *no* handgun bullet travels fast enough to overcome the elasticity of tissue: penetration and expansion. The damage done by a handgun bullet is simply whatever tissue is destroyed along its flight path. This is very insightful:
http://www.m4carbine.net/showthread.php?t=44227