Humour is so complex a part of human communication, that analysing it feels a bit like dissecting a live frog to understand how it works—you separate the components, but kill the frog in the process.
Making someone smile or laugh is one of the most effective ways of communicating, for even with differences in language, visual comedy creates a bridge...and that needn't be a banana peel prat fall, for something as simple as a facial expression forms empathy. One theory of humour says that we laugh at what we fear, which is both a sign of nervousness and the resilience of the human spirit; it explains all of the jokes about cock size, sexual activity, foreigners and the ultimate killjoy—death!
Humour in a group is altered by it being a social interaction—because the people surrounding us are laughing, we laugh—even if we're not sure of why something is funny. We've joined hive mind, and our laughter is a mild form of hysteria. This is relevant when you consider what we do as writers, for reading is a solitary activity. Sure, you may read a review of a humorous book that encourages you to seek it out, but the author still needs to tickle your funny bone in a way that you relate to. Short of telling one joke after another, piling up witticisms, written humour is dependent on situational comedy—how the characters relate to one another—what misunderstandings they have.
What one person finds funny, another will be offended by. In this way, humour can separate people, rather than being a unifying force. Just think of some of the spiteful jokes told about tragedies, normally labelled 'black humour'. I've had to address this issue in my crime novels, where the detectives, doctors, nurses, pathologist and coroner deal with horrendously violent and tragic injuries and deaths—sometimes using tasteless jokes as a way of easing the tension.
As comedy film director Mel Brooks said: "Humor is just another defense against the universe."