I agree about the trained person, but untrained person, no fuckin way. They might get lucky, but just as likely they won't. Knives are also good self defense in trained hands, but absolutely terrible in untrained hands. Probably just as or more likely to get lucky with a knife too unless you are dumb enough to try throwing it.
Pepper spray is much more effective in untrained arms than either.
There are many situations, so it's really hard to go through all of them. Getting mugged on the street is very different than someone invading your house. Getting mugged on the street if the person is unarmed, you can't shoot them. If they have a knife, you are extremely likely to get cut pulling your gun, and if you have a gun, as long as the thug is willing to shoot, he'll try shooting before you can pull your gun. Admittedly, you are probably best off just giving your wallet in these cases. Any type of self defense is just a hope and a prayer.
If it's a home invasion, I would say a shot gun is good, but a hand gun, not as much, only if your are trained to shoot.
Home defense in general, a dog is much better. It's always there to bark and attack invaders. Guns can only protect your house if you are home. Guns are also often targeted items for thieves.