Don't answer door with gun visibly in hand, for one thing. Anything dangerous enough to require answering the door with gun visible, is too dangerous to be answering at all.
Closed circuit TV, or at the very least an intercom at the door, ain't a bad idea. Only the rich had those when I was young; today they're affordable by most everyone.
Finally, when in doubt, a call to 9-1-1 should quickly determine if whoever's at your door is the police.