Think of Berlin in the literature of the 20th century, and the images that spring to mind arealmost always chillingly ominous. From the Weimar Republicto the Berlin Republic, a dark, brooding atmosphere infuses even the zanier, wildly licentious scenes. It’s a sexual revolution (before the term was coined) coupled with rampant violence and looming repression. It’s total freedom joined to total desperation one moment–followed by both brands of this century’s totalitarian horrors the next. And then there’s Berlin as the centerpiece of the cold war, the setting that consistently beat out all others for maximum drama.

Christopher Isherwood, a British writer who later became an American citizen, immortalized the Berlin of the late 1920s and early 1930s in “The Berlin Stories.” He reveled in the city’s decadence and produced a host of dubious, amoral, likable characters like Sally Bowles–who would later be reincarnated onstage and in the movie “Cabaret.” And Isherwood foreshadowed tragedy in the making. “But isn’t there a natural instinct for freedom?” his fictional hero (also called Isherwood) asks. Another character replies: “Yes, you are right. But the boys soon lose it. The system helps them to lose it. I think perhaps that, in Germans, this instinct is never very strong.”

Both the real and the fictional Isherwood were attracted to Berlin’s outlandish reputation. In his novel “Down There on a Visit,” the hero is lectured by a distant relative who lived in Germany about Berlin’s “vilest perversions” and “nauseating” sexual practices. “That city is doomed, more surely than Sodom ever was,” the relative warns. “Those people don’t even realize how terribly low they have sunk.” Which only convinces Isherwood to get to Berlin as soon as possible. That was the Berlin where, according to Bertolt Brecht’s lyrics, there’s a rationale for letting loose. “Do everything tonight that is forbidden,” his song urges. “When the hurricane comes, it’ll do exactly the same.”

Most fiction of the period offers up less appealing characters than Isherwood does. In his classic German novel “Berlin Alex-anderplatz,” Alfred Doblin presents a parade of primitive lowlifes. Chief among them is his antihero Franz Biberkopf, “that rough uncouth man of repulsive aspect” who emerges from prison after serving time for killing his girlfriend–and promptly gets mixed up with the wrong crowd again. Vladimir Nabokov, who lived in Berlin for much of this period but never learned German, observed the city’s inhabitants with icy detachment. He described the sunbathers in the Grunewald, an affluent district with a forest and lake, by pointing out “the pimply shoulder blades of bandy-legged girls; the sturdy necks and buttocks of muscular hooligans; the hopeless, godless vacancy of satisfied faces.”

Nothing, however, could lessen the magical pull the city exuded in the 1920s. German playwright Carl Zuckmayer tried to convey Berlin’s allure by comparing the city to a woman. “Some saw her as hefty, full-breasted, in lace underwear, others as a mere wisp of a thing, with boyish legs in black silk stockings,” he explained. “The daring saw both aspects, and her very reputation for cruelty made them the more aggressive. To conquer Berlin was to conquer the world.”

When the Nazi terror and World War II were in full swing, fiction was less effective than nonfiction at conveying the city’s atmosphere. In “Berlin Diaries, 1940-1945,” Marie Vassiltchikov, a White Russian princess who hobnobbed with the German aristocracy, described the clean sweep of her friends after some of them were implicated in the July 20, 1944, botched assassination of Hitler. “Wherever I turn, everybody is disappearing one by one; there is nobody left whom one can ask for help,” she wrote. “They are now arresting people who were mere acquaintances or who happened to work in the same office.” But after the terror of the war, both the city’s racy and cultural sides blossomed again. In his novel “Armageddon,” American writer Leon Uris described a “wonderful, wicked, wild city”–that was also" a pompous and proper place with the highest order of opera and concerts." As the cold war took over, a new type of gloom descended. But even then, there was something tantalizing about a divided city where, as Le Carre put it–again in “The Spy Who Came In From the Cold”–“intelligence was… so much a part of the daily life of Berlin that you could recruit a man at a cocktail party, brief him over dinner and he would be blown by breakfast. For a professional, it was a nightmare: dozens of agencies, half of them penetrated by the opposition, thousands of loose ends; too many leads, too few sources, too little space to operate.”

But for East Berliners, there was nothing romantic about the period. The heroine of “Flight of Ashes,” a 1981 novel by Monika Maron, the daughter of a former East German Interior minister, spoke for an entire generation. “I’m being cheated out of myself,” she complains. “I’m not even talking about the fact that I’ll die in the age of space exploration without having taken a walk in Montmartre, without knowing what it smells like in the desert or what a fresh oyster tastes like… The greater deception: they are cheating me out of me, out of my qualities. I’m not allowed to be everything I am.”

And today’s post-wall, post-cold-war Berlin? So far, the literature on the subject is amazingly skimpy. In “All Souls’ Day,” a recent novel by Dutchman Cees Nooteboom, a Dutch TV cameraman admires the city and its new openness: “This was one of the reasons why he loved Berlin. He always had the feeling that he was on an endless plain that stretched far into Russia.” But the hero knows that Berlin itself remains divided, with “a scar that you would be able to see for a long time.” In a recent collection of crime stories, German writer Thea Dorn offers a grim personification of the city: “Now Berlin was far into the ’90s, suffering from a hangover after a late-in-life honeymoon and having to share its modest pension with a spouse that had already gotten on its nerves on their wedding night.”

So does pessimism triumph again, even at a time when it would seem optimism should have its moment? Perhaps: but that is very much in the Berlin tradition. Listen to Kurt Tucholsky, the famed left-wing journalist and satirist, describing Berlin before he committed suicide in 1935: “Berliners… growl at each other in the streets and subways since they don’t have much in common. They don’t want to know anything about each other, and each lives for himself. Berlin combines the disadvantages of an American big city with those of a provincial German town. Its merits can be read in Baedeker’s.” In other words, don’t expect writers to look on the city’s bright side. They never have.