Ammo is a BIG cost in firearms. Top Notch 9mm ammo has PLENTY of power for self defense...and plinking ammo is a lot less expensive in 9mm than in 40SW. If cost is a factor to you, I'd strongly suggest going 9mm.
The bottom line for reliable self defense weapons, talking NEW or 'almost new' is probably $300 -350
That will get you a Smith and Wesson Sigma or a Ruger P95. No one will laugh, but no one will be highly impressed. The sigma has great ergonomics, is reliable, but just isn't terribly accurate. The gun will definately be able to put all shots on a paper plate at 25 yards (something a lot of shooters can't do) but it won't be getting 2 inch groups at 25 yards. The Ruger P95 won't win any beauty contests but it isn't butt ugly either. It is very solid and very reliable...but it is built like a brick. It is blockish, and while I bought one I am selling it simply because it is too wide for my hands.
(The funny thing is, the pistol Ruger replaced the P95 with, the SR9...available only in 9mm, 17 shot, $400, maybe $420... is the slimmest doublestack 9mm out there.)
a step up in price but not really much improvement in quality is the Taurus Millenium and Taurus 24/7 It falls between the two...better ergonimics than the Ruger p95, but better accuracy than the Sigma. If the Ruger 95 doesn't fit your hand i'd look at the Taurus, but otherwise I'd go ruger on a budget.
Stepping up to about $450-500 you have a lot of good choices. Glock, Springfield XD, Smith&Wesson MP, Taurus 92 (Taurus copy of the Beretta 92), Taurus's 'improved' 24-7, the Taurus 24-7 OSS, CZ-75 (I recommend you check that one out) Sig 2022 (IMHO this is 'sig economy' not really worthy of the name) SIG 250 (this one is a tad more expensive, but it has a WONDERFUL trigger, but is Double Action Only striker fire..but still find one and try that trigger pull)
Now, if you step up to about $650 you get the springfield XDM, Walther P99, H&K, some Sig more worthy of the name, etc. But there is absolutely NO reason you need to be in this price range. $450 +/- $50 should be able to get you a FINE firearm in 9mm OR in 40SW
I suggest getting your paws on these and seeing how they feel, see how much they want for them, before finalizing your decision on the Glock
Sig 250
Springfield XD, full size and compact (and subcompact I suppose if you really want small)
Smith and Wesson M&P
CZ-75 (75B, 75 Compact, or 75 P01)
CZ-P07 (polymer frame, but very similar to above)
Ruger SR9
Taurus 92
You may end up back at the glock, and that is fine. Glock makes an excellent gun. Just by then you'll be arriving at the decision to buy a glock fully informed of your other choices