I recently re-watched the last scene of Blackadder. Spoilers follow, so if you haven't seen it, look away now.
This is one of the most famous shifts in tone ever in television - probably in popular fiction. After a series which managed to make trench warfare in WWI funny, the final series ends with an unexpected tragedy. Our characters go over the top to their deaths, like so many servicemen did in those four awful years.
I have always felt the finale is brilliantly done. The episode is funny right up until seconds before the famous closing montage and it follows exactly the same formula as the rest of the series - Blackadder trying ever more elaborate ways to avoid going over the top. Baldrick's final cunning plan, which we don't get to hear, just makes the first-time viewer even more convinced that something will happen and they'll be saved. And Captain Darling, whom nobody likes, being sent to die by the General he's served faithfully for years is heart-breaking. Technically speaking the last scene isn't great - I heard somewhere that the slow-motion and limited soundtrack were suggested because the special effects looked so poor, but it has an emotional impact unlike anything else I've seen in a TV comedy.
And no credit sequence either - it's the last episode of the last series and there's nothing to say who made it. Because it wasn't important, compared to what it was trying to say.
I don't write comedy (which is weird because I love it), but I have always felt there is legitimate humour in everything. I try not to joke about other people's serious stuff unless they do it first or I know them very well, but the most serious things in life are funny. Death is funny, and if you don't believe me, read Woody Allen's prose on the subject ('Is there an afterlife, and will they be able to break a twenty?'). Panic attacks, which I suffer from, are very funny (I admit I don't tend to see the humour during them, but during them I couldn't be relied upon to see a jumbo jet headed for my patio doors at speed). Illness is funny. World War One, it turns out, is very funny, when the Blackadder crew are involved.
But when we laugh at the darkest moments in our lives, it's not to trivialise them. It's to fully experience the richness and complexity of them. Sad times can be funny. Funny moments can be tragic. No one would think you were odd for tearing up a little on your wedding day when you thought of all the people who couldn't be there. So why do we get freaked when someone can laugh or smile at a funeral or at a hospital bedside?
And I think that good writing can do that - drag those strange contradictory moments on to centre stage and make them dance. It can keep us laughing right up until the boys go over the top of the trenches after Captain Blackadder's final 'Good luck, everyone.' It can make readers writhe with sympathy for Amber St Clare although they *know* what an amoral trollop she is. Terry Pratchett is especially great at that contradiction, keeping readers laughing even as they wonder if Sam Vimes could be called a murderer for what he just did.
So how on earth does one do it?
Well. Being a genius helps.
And the rest of us? I guess if we ever find out, we should agree to tell each other. . .