“AND,” my friend said, “Terry Pratchett lives just down the road!”

We’d been discussing Wiltshire as a place to live – my friend had recently moved there. I’m an irredeemable urbanite. I can’t imagine living more than a five-minute walk from my fellow human beings. Other people are vital to my peace of mind.

Still, I had to admit the Pratchett connection was a powerful plus.

“Do you see him a lot?” I asked.

“Almost every day. He walks past the bottom of my garden.”

“What’s he like?” I asked.

My friend sighed. “Mostly, he’s a hat,” he said. “The hedge is just a little bit shorter than he is, so I see his hat and occasionally an ear as he goes by.”

After that, we sat quietly for a while, until finally my friend said: “I suppose one day, if the wind’s strong enough, it might blow off.”

The man who died last week was possessed of a talent so magnetic that a perfectly rational person would sit in the garden day in and day out, hoping for a meteorological caprice to reveal the top of his head. I never met him, though I have loved his work since 1983, and now I think that will be my enduring image of him: a peripatetic black hat seen over a hedge, like the tip of a very funny iceberg.

That year, 1983, was when the first Discworld book was published. In quick succession, The Colour of Magic deflates two princes of fantasy, Fritz Leiber and Robert E Howard, and several of their successors. The Discworld is merrily and efficiently corrupt, as if Captain Renault, the cop in Casablanca, were given jurisdiction over Middle-earth. Trolls work as nightclub bouncers and peddle illegal mineral compounds to one another; the university where the wizards learn hidden secrets is a cross between a heavily armed city livery company and a Borgia soup-tasting. Before Pixar ever talked about making every frame in a movie hilarious and wondrous in some tiny way, Pratchett was doing the same thing in the pages of his books. He never stopped teasing the canon, either, even as the stories grew more nuanced and complex: in Going Postal – one of my favourites, in which a captured conman is set to work revitalising the Post Office – a group of wizards struggling to locate a missing person with a magic lens irritably complain at finding Sauron’s “damn enormous fiery eye” glaring balefully at them across the gulf between one well-loved series and another. While Game of Thrones and others tell us about the darkness, the Discworld floats obstinately through space on the back of a giant turtle. Pratchett is a writer who numbered among his early creations a walking suitcase whose dog-like loyalty and cat-like lethality were matched only by its comic timing.

Reading the news after his death was announced, you could almost have believed that Pratchett was primarily a commentator on the human heart or a revealer of societal insanity. He was those things, of course, but more: Pratchett was genuinely, reliably funny. Even his less funny books were funny. We should add him to that infamous list – pizza, sex and Terry Pratchett. Even when they’re bad, they’re still pretty damn good.

We have a curious relationship with funny in the UK. We love to laugh, but we also think that making people laugh is just a little bit second-tier, especially in a literary context. We’re not actually a gloomy, introspective bunch, but we somehow aspire to be. We do have a local written heritage of doomed beauty, and we bathe in it – Wilfred Owen and Rupert Brooke under fire in the trenches, Keats dying consumptively, Byron brooding and Shakespeare’s Romeo and Juliet almost wilfully mooning their way to the grave – but to be honest, I blame Tolstoy. The opening line of Anna Karenina shaped our modern understanding of the profound: “Happy families are all alike; every unhappy family is unhappy in its own way.” It’s utter nonsense. Happiness is boundlessly weird. Other people’s choices often seem to delight them, where I would run screaming. But Tolstoy’s elegant lie has settled in our minds, and now we believe that joy is endlessly and easily duplicated and therefore cheap, whereas sorrow possesses a uniqueness that makes it worthy of study. Pratchett was pert with his detractors: “Stories of imagination tend to upset those without one.” He might have said the same thing about a sense of humour, and that two-fisted partisanship, the willingness to hit back at an occasionally superior response to his work, made him kin to much of his audience, who had to defend their reading choices – especially in the 80s, before the 90s geek revolution made our obsessions cool – against charges of meaninglessness or childishness.

From this vantage it is an absurd complaint, for all that the earlier books are less sophisticated. Pratchett was a master of the one-liner and the long gag. He could drop a laugh on you out of the blue to puncture a serious situation or just because it was there, but he could slow-burn a joke too, so that it was bound into the fabric of a story and when the punchline came, it not only made you howl with laughter but also solved some fearsome quandary in the story. That doesn’t mean he didn’t have anything to say. He rose from relative unknown to megastar in a few years, and rather than becoming cautious he got better and bolder. Small books became longer ones, fast gags became deep. His friend and collaborator Neil Gaiman wrote recently that Pratchett was driven in part by rage – of various kinds – and perhaps all great comedy must be. Certainly he declared war on his illness when he was diagnosed with Alzheimer’s disease in 2007, acknowledging his enemy but dismissing it with typical light contempt as “an embuggerance”.

He took on the rough stuff in his writing because he was fundamentally writing about people, even if those people were the stuff of dreams. The off-kilter examination of the interior lives of those minor characters in fantasy stories whose role is to come in and get slaughtered (Guards! Guards!) became first a riff on noir, and then a backhanded look at class and responsibility, as protagonist Sam Vimes rose in the society of Pratchett’s imagined city of Ankh-Morpork. The three witches from Macbeth gave rise first to a ribald comedy (Wyrd Sisters) and then a funny yet wise examination of how stories shape life (Witches Abroad), before Pratchett unleashed a series of books allegedly for kids, featuring a girl protagonist named Tiffany Aching, who has her head screwed on right and needs no salvation from anyone.

Sir Terry Pratchett – he was knighted in 2009, and on him it looked earned rather than entitled – wrote about dragons, wizards, turtles, witches, time‑travelling monks and suitcases with legs. He wrote about constructing planets and he wrote about people so tiny they live in carpets. At the same time and in the same breath he wrote about religion, football, jingoism, war, fatherhood, age, isolation and sexism; about fairness and unfairness, about narrative and Death and obligation, and about the heartlessness of bureaucracy and the deadliness of ignorance.

The dark secret of literature is that it’s not hard to write about serious topics, but Pratchett did it so well that half the time you don’t spot it. Along with the Discworld and the Luggage, The Colour of Magic also introduced Rincewind: a wizard who has accidentally filled his head with a magic so important that he can’t do any lesser spells. If you want to break it down, Rincewind’s stories are about aspiration and identity, about promises of how things ought to work being betrayed by a world that doesn’t deliver and then laughs at your sense of foul play, at least as much as they are about a weaselly bloke trying and failing to find a quiet life. There’s a bleak irony in Rincewind’s plight now, too: the first hero of the Discworld couldn’t do magic because there was something alien and unwelcome lurking in his head.

But that kind of dissection is, for me at least, not the point. There’s no need to break Pratchett down, to find traces of sorrow so that we can lay claim to significance for this writer, these books. They can walk that walk, sure, but so can plenty of others who can’t or won’t be funny. He was funny. Funny doesn’t benefit from analysis, and analysis doesn’t truly understand it or why we need it so much. Funny happens and it makes the world bright, and then it’s gone, and all you have left is what I have today: the image of a black hat and an ear behind a hedge.

• Nick Harkaway's latest novel is Tigerman.