I admire humor in writing, and have made some attempts to add a pinch of humor to my style. This is much easier said than done.
Getting a laugh is hard enough in person, with visual aids and alcohol, but in writing,
Humor is a Serious Bitch.
John Cleese wrote a bit on the mechanics of humor. He said It involves the unexpected. It has a Shock factor that makes the body convulse, or the mind repulse.
These are also the core elements of trauma, therefore, when attempting humor, it seems wise to have a well trained EMT nearby.
Another thing I noticed in my research is that people with big egos make poor humorists, unless of course their ego is so incredibly large that it is laughable in its own right. Aside from that, most jokers use the persona of "Hey, Im a dumb jerk" This gives them the freedom to speak on any issue without the need for credibility.
Lastly, there is the need for rhythm. The joke has got to roll like music to a beat, usually to a 1,2,3 set up. One and two set the expectation for three, but three is the opposite of what is expected and the result is convulsion or repulsion, either in the form of a hearty laugh or a heart attack.
I know that wasn't very funny...But Im working on it.