Writing humor is not something that all writers undertake.
Some dramatic novelists might stick in a silly scenario or sarcasm, but they'll steer clear of riddling their work with gags for fear it won't be taken as a "serious" work. Some non-fictionalists won't sully their work with a single dirty phrase for fear of appearing (cringe) unprofessional.
But, mostly, writers won't even dare attempt humor because humor is hard to write. Humor is a balancing act. One word out of place, one emphasis, and the joke spills into: book closed.
Carl Hiaasen, however, has a real knack for word choice (diction) and humor such that the driving force of his humor is not just the ridiculous and entertaining scenarios his crazy characters find themselves in, but also what words he chooses for his prose.
An example from his 2013 novel, Bad Monkey:
It's not easy to have a seriously deep conversation when you've got a purple hard-on that could cut a diamond.And another!
Eve went to the kitchen and came back with an empty wine bottle [for her husband, Stripling, to pee in].And another?
Stripling scowled. "Get serious. My dick won't fit in there."
"Sure it will."
"It's bigger than a goddamn cork!"
Driggs [the bad monkey] would have grinned had his incisors not been so deeply implanted in Egg's fleshy thing, to which the monkey clung as if it were the bough of a mahogany tree.Now, let's shake out what makes these lines humorous. Much of it is the delivery. As the eye scans word-to-word and (as science teaches us) actually jumps forward and backwards across a sentence as we read, the pun dawns on us. The gist of the joke.
Yancy needed a moment to absorb the scene. "Jesus," he said. "The man's got a monkey on his dick."
But also important is just what word you use. Or the diction in your dick jokes...
Let's look at Hiaasen's examples: "purple" and "cut a diamond" ; "goddamn cork" ; "deeply" "fleshy" "bough of a mahogany tree".
Here we have not only adjectives describing the various dicks popping up throughout the text, we also have adjective-conjoined nouns which Hiaasen uses to compare these various cocks to. (It's funny when genitalia are given new names, like woowoo or hooha, but also when compared to seemingly incomparable things, such as things that are hard or large, or—humorous twist—soft or small.) Not only are these word choices creative and strong word choices, they're also deftly, congenially surprising and, thus, pun-inducing—which is more than half the battle of achieving humor.
Another lesson of humor is how it loosens any tension there might be between the author and the reader. A lubrication, of sorts.
That said, I'm out.