I would take 9 over .40 any day. I've got a good bit of experience with various .40 S&W chambered handguns including the ones I've owned and can affirmatively say that I prefer 9 over .40 and .45 over both. The way I see it is this, the .40 packs a hell of a punch, but recoil is fairly strong. Bullet weight wise, you run anywhere from 135gr to 180 gr, so basically a super lightweight extreme high velocity .45 up to a typical .45 +P loading. Yes you can cram a few more rounds of .40 into a mag than for a similarly sized .45, but for as snappy as the .40 recoils, I'd rather just have a .45.
On the other hand if you get a 9 with the right load, you can getplenty of ammo and good ballistic performance. In a 9mm, you can get anything from 10 to 19 rounds in a standard sized mag, depending of course on where you live (i.e. are you in a restricted mag capacity state) and what gun you have (Sig 226 for 15+1, XD9 full size at 16+1, Glock 17 at 17+1, and XD-M at 19+1), you can get plenty of ammo that's effective with the right load, and much softer on the recoil end allowing for easier on target follow up shots.
I had a USP Compact in .40, a Walther P99QA in .40, two Glock 23s, and I've shot several different Sigs in .40. I honestly prefer my .45 1911 over any .40 chambered handgun if I want a heavier round, and if I want mag capacity, high velocity, and a ease of quick and accurate follow up shots, I'll take a 9. FWIW, I carry a .45 1911 daily.