This is something I learned in grade school, but it’s been awhile so my information may have been debunked in the last 30 years or so.
As I understand it, houseflies are covered in hairs that can detect sudden changes in the air caused by flat objects with lots of air resistance – like your hand – flying towards it.
Like make a fanning motion towards your face as though you were cooling yourself – feel that air moving on your face? A housefly is at least ten times more sensitive to that and moves out of the way before your hand even has time to get halfway there.
A fly swatter, on the other hand, has holes in it that allow air to pass right through it so that the fly never feels it coming. A blade or whip has something of the same effect – assuming your aim is good enough to bisect a fly.
On a more interesting note, carnivorous plants take a more methodical approach, moving ever so slightly when a fly lands on it as to not alert it, only moving quickly when there’s no room for the prey to maneuver.
Latest Answers