Sharks are opportunistic scavengers for the most part. They can tell there is blood in the water from a long, long way off. And when they arrive, if they find a critter (fish, seal, human, whatever) struggling, splashing and generally looking distressed, it gets the sharks attention and they will try to investigate. That usually means swimming up close, circling, bumping it's nose into that critter and maybe even taking a bite to see if it's edible.
Most people don't deal well with sharks or adrenaline, and when a shark gets really close, most people's adrenaline levels go through the roof. It's a bad mix.
But IMHO, the best thing you can do is keep an eye on the shark and stay calm (I read that somewhere recently... (see post #2). I've seen a couple of good size sharks while snorkeling out on open water reefs (as opposed to shallow water patch reefs). And even with dozens of snorkelers in the water, the sharks showed no attention and just swam by. This is probably the case in 99.99% of shark sightings by snorkelers and divers. And most sharks that snorkelers see aren't big enough to want to try to attack a human. In 15 years in Florida and snorkeling on average 4 or 5 long weekends a year, I've never seen a shark that was more than 6' to 8' long.
If one started to circle me I'd temporarily stop swimming and moving as little as possible while watching the shark and trying to keep it in front of me. If I think it's just looking and not seriously interested (like I can read the shark's mind) I'd slowly start to head for the boat trying not to make any more commotion or splashing than absolutely necessary. If the circling is more menacing then I'd try to keep arms and legs pulled in toward my body as much as possible making for less easy things for the shark to bite. If it swims at me, I'll do my best to be ready to try and move off to the side of the shark and as it goes past, punch it in the side. In the gill slits or the eye may even be better, but just get the punch in. Sharks aren't fighters, if you get in a good blow they are far more likely to swim off and leave you alone than to turn and attack you again. They are opportunists not fighters. But once they feel you are food, usually after they have bitten and there is a lot of blood in the water, they are not inclined to give up easily.
Here is some helpful info from the Florida Fish and Wildlife Commission:
http://myfwc.com/research/saltwater/sharks-rays/shark-attacks/
From 1882 thru 2015 in Monroe County (the Florida Keys) there have been just 19 reported shark attacks on humans. That averages out to 1 shark attack every 7 years!
http://www.flmnh.ufl.edu/fish/isaf/shark-attacks-maps-data/north-america/florida/