Here's another vote for 9mm. I'll break it down into categories.
For personal defense (the only place where a strong case can be made for the .40): The differences in terminal performance on humans between a 9mm, .40, and even .45 are pretty marginal. You will be able to shoot the 9mm faster, and perhaps more accurately, than the .40. If you buy the current view that handgun bullets just poke holes, is an extra .04" of hole width worth the tradeoff of fewer holes in total (due to both capacity and rapidity of fire)? Modern 9mm SD/service ammo meets FBI standards and is plenty potent. If you don't agree, the answer is to move off the service-caliber power band entirely and go to a 10mm or magnum revolver cartridges or the like.
Hunting: Neither round is a good choice for hunting, so no points for either.
Practice: Strong win for the 9mm here, from both cost of ammo and for development of a flinch-free shooting form.
Gun games: 9mm is the better cartridge for IDPA; .40 gets to major in USPSA.
Safety: The 9mm, and guns chambered in it, are very "safe," insofar as a cartridge can be safe. The .40 (although pretty safe when you consider the vast number of rounds of it fired every year) has some issues. Bullet setback quickly leads to a compressed, over-pressured load in a .40, which can result in case rupture and ka-booms.
By my scorecard, unless you're going to shoot USPSA and want to hit major scoring, the 9mm is the all-rounder winner.