Some scholars[who?] have suggested that certain ancient and religious texts bear similarities to what would later be called detective fiction. In the Old Testament story of Susanna and the Elders (the ProtestantBible locates this story within the apocrypha), the account told by two witnesses breaks down when Daniel cross-examines them. The author Julian Symons has commented on writers who see this as a detective story, arguing that "those who search for fragments of detection in the Bible and Herodotus are looking only for puzzles" and that these puzzles are not detective stories.[1] In the play Oedipus Rex by Ancient Greek playwright Sophocles, the title character discovers the truth about his origins after questioning various witnesses. Although "Oedipus's enquiry is based on supernatural, pre-rational methods that are evident in most narratives of crime until the development of Enlightenment thought in the seventeenth and eighteenth centuries", this narrative has "all of the central characteristics and formal elements of the detective story, including a mystery surrounding a murder, a closed circle of suspects, and the gradual uncovering of a hidden past."[2]

The earliest known example of a detective story was The Three Apples, one of the tales narrated by Scheherazade in the One Thousand and One Nights (Arabian Nights). In this story, a fisherman discovers a heavy, locked chest along the Tigris river and he sells it to the Abbasid Caliph, Harun al-Rashid. When Harun breaks open the chest, he finds inside it, the dead body of a young woman who has been cut into pieces. Harun then orders his vizier, Ja'far ibn Yahya, to solve the crime and to find the murderer within three days, or be executed if he fails in his assignment.[3]Suspense is generated through multiple plot twists that occur as the story progresses.[4] This may thus be considered an archetype for detective fiction.[5]

The main difference between Ja'far ("The Three Apples") and later fictional detectives, such as Sherlock Holmes and Hercule Poirot, is that Ja'far has no actual desire to solve the case. The whodunit mystery is solved when the murderer himself confesses his crime.[6] This in turn leads to another assignment in which Ja'far has to find the culprit who instigated the murder within three days or else be executed. Ja'far again fails to find the culprit before the deadline, but owing to his chance discovery of a key item, he eventually manages to solve the case through reasoning, in order to prevent his own execution.[7]

The hero/detective of these novels is typically a traditional judge or similar official based on historical personages such as Judge Bao (Bao Qingtian) or Judge Dee (Di Renjie). Although the historical characters may have lived in an earlier period (such as the Song or Tang dynasty) most stories are written in the latter Ming or Qing period.

These novels differ from the Western tradition in several points as described by van Gulik:

the detective is the local magistrate who is usually involved in several unrelated cases simultaneously;

the criminal is introduced at the very start of the story and his crime and reasons are carefully explained, thus constituting an inverted detective story rather than a "puzzle";

the stories have a supernatural element with ghosts telling people about their death and even accusing the criminal;

the stories are filled with digressions into philosophy, the complete texts of official documents, and much more, making for very long books;

the novels tend to have a huge cast of characters, typically in the hundreds, all described as to their relation to the various main actors in the story.

Van Gulik chose Di Gong An to translate because it was in his view closer to the Western tradition and more likely to appeal to non-Chinese readers.

One notable fact is that a number of Gong An works may have been lost or destroyed during the Literary Inquisitions and the wars in ancient China. Moreover, in the traditional Chinese culture, this genre had a low prestige, and was much less considered preserving than works of philosophy or poetry. Only little or incomplete case volumes can be found; for example, the only copy of Di Gong An was found at a second-hand book store in Tokyo, Japan.

"Das Fräulein von Scuderi", an 1819 short story by E. T. A. Hoffmann, in which Mlle de Scudery establishes the innocence of the police's favorite suspect in the murder of a jeweller, is sometimes cited as the first detective story and a direct influence on Edgar Allan Poe's "The Murders in the Rue Morgue" (1841).[11] Also suggested as a possible influence on Poe is ‘The Secret Cell’, a short story published in September 1837 by William Evans Burton, describing how a London policeman solves the mystery of a kidnapped girl. Burton’s fictional detective relies on practical methods—dogged legwork, knowledge of the underworld and undercover surveillance—rather than brilliance of imagination or intellect, but it has been suggested this story may have been known to Poe, who in 1839 worked for Burton.[12]

Detective fiction in the English-speaking world is considered to have begun in 1841 with the publication of Poe's "The Murders in the Rue Morgue" itself,[8] featuring "the first fictional detective, the eccentric and brilliant C. Auguste Dupin". When the character first appeared, the word detective did not even exist. However, the character's name "Dupin" originated from the English word dupe or deception.[13] Poe devised a "plot formula that's been successful ever since, give or take a few shifting variables."[14] Poe followed with further Auguste Dupin tales: "The Mystery of Marie Rogêt" in 1843 and "The Purloined Letter" in 1845.

Poe referred to his stories as "tales of ratiocination".[8] In stories such as these, the primary concern of the plot is ascertaining truth, and the usual means of obtaining the truth is a complex and mysterious process combining intuitive logic, astute observation, and perspicacious inference. "Early detective stories tended to follow an investigating protagonist from the first scene to the last, making the unraveling a practical rather than emotional matter."[14] "The Mystery of Marie Rogêt" is particularly interesting because it is a barely fictionalized account based on Poe's theory of what happened to the real-life Mary Cecilia Rogers.

Émile Gaboriau was a pioneer of the detective fiction genre in France. In Monsieur Lecoq (1868), the title character is adept at disguise, a key characteristic of detectives.[15] Gaboriau's writing is also considered to contain the first example of a detective minutely examining a crime scene for clues.[16]

Another early example of a whodunit is a subplot in the novel Bleak House (1853) by Charles Dickens. The conniving lawyer Tulkinghorn is killed in his office late one night, and the crime is investigated by Inspector Bucket of the Metropolitan police force. Numerous characters appeared on the staircase leading to Tulkinghorn's office that night, some of them in disguise, and Inspector Bucket must penetrate these mysteries to identify the murderer. Dickens also left a novel unfinished at his death, The Mystery of Edwin Drood.[17][18]

Wilkie Collins

Dickens's protégé, Wilkie Collins (1824–1889)—sometimes referred to as the "grandfather of English detective fiction"—is credited with the first great mystery novel, The Woman in White. T. S. Eliot called Collins's novel The Moonstone (1868) "the first, the longest, and the best of modern English detective novels... in a genre invented by Collins and not by Poe",[19] and Dorothy L. Sayers called it "probably the very finest detective story ever written".[20]The Moonstone contains a number of ideas that have established in the genre several classic features of the 20th century detective story:

Although The Moonstone is usually seen as the first detective novel, there are other contenders for the honor. A number of critics suggest that the lesser known Notting Hill Mystery (1862–63), written by the pseudonymous "Charles Felix" (later identified as Charles Warren Adams[21][22]), preceded it by a number of years and first used techniques that would come to define the genre.[21][23]

Literary critics Chris Willis and Kate Watson consider Mary Elizabeth Braddon's first book, the even earlier The Trail of the Serpent (1861), the first British detective novel.[24] The novel "features an unusual and innovative detective figure, Mr. Peters, who is lower class and mute, and who is initially dismissed both by the text and its characters."[24] Braddon's later and better-remembered work, Aurora Floyd (printed in 1863 novel form, but serialized in 1862-63[25]), also features a compelling detective in the person of Detective Grimstone of Scotland Yard.

Tom Taylor's melodrama The Ticket-of-Leave Man, an adaptation of Léonard by Édouard Brisbarre and Eugène Nus,[26] appeared in 1863, introducing Hawkshaw the Detective. In short, it is difficult to establish who was the first to write the English-language detective novel, as various authors were exploring the theme simultaneously.

The period of the 1920s and '30s is generally referred to as the Golden Age of Detective Fiction. During this period, a number of very popular writers emerged, mostly British but with a notable subset of American and New Zealand writers. Female writers constituted a major portion of notable Golden Age writers, including Agatha Christie, the most famous of the Golden Age writers, and among the most famous authors of any genre, of all time. Four female writers of the Golden Age are considered the four original "Queens of Crime": Christie, Dorothy L. Sayers, Ngaio Marsh and Margery Allingham. Apart from Ngaio Marsh (a New Zealander) they were British.

Various conventions of the detective genre were standardized during the Golden Age, and in 1929 some of them were codified by writer Ronald Knox in his 'Decalogue' of rules for detective fiction, among them to avoid supernatural elements, all of which were meant to guarantee that, in Knox's words, a detective story "must have as its main interest the unravelling of a mystery; a mystery whose elements are clearly presented to the reader at an early stage in the proceedings, and whose nature is such as to arouse curiosity, a curiosity which is gratified at the end." In Golden Age detective stories, an outsider—sometimes a salaried investigator or a police officer, but often a gifted amateur—investigates a murder committed in a closed environment by one of a limited number of suspects.

The most widespread subgenre of the detective novel became the whodunit (or whodunnit, short for "who done it?"), where great ingenuity may be exercised in narrating the events of the crime, usually a homicide, and of the subsequent investigation in such a manner as to conceal the identity of the criminal from the reader until the end of the book, when the method and culprit are revealed. According to scholars Carole Kismaric and Marvi Heiferman, "The golden age of detective fiction began with high-class amateur detectives sniffing out murderers lurking in rose gardens, down country lanes, and in picturesque villages. Many conventions of the detective-fiction genre evolved in this era, as numerous writers—from populist entertainers to respected poets—tried their hands at mystery stories."[14]

The "puzzle" approach was carried even further into ingenious and seemingly impossible plots by John Dickson Carr—also writing as Carter Dickson—who is regarded as the master of the "locked room mystery", and Cecil Street, who also wrote as John Rhode, whose detective, Dr. Priestley, specialised in elaborate technical devices, while in the US the whodunit was adopted and extended by Rex Stout and Ellery Queen, among others. The emphasis on formal rules during the Golden Age produced a variety of reactions. Most writers were content to follow the rules slavishly, some flouted some or all of the conventions, and some exploited the conventions to produce new and startling results.

By the late 1920s, Al Capone and the Mob were inspiring not only fear, but piquing mainstream curiosity about the American underworld. Popular pulp fiction magazines like Black Mask capitalized on this, as authors such as Carrol John Daly published violent stories that focused on the mayhem and injustice surrounding the criminals, not the circumstances behind the crime. From within this literary environment emerged many stories and novels about private detectives, also known as private investigators, PIs and "private eyes" ("eye" being the vocalization of "I" for "investigator"). Very often, no actual mystery even existed: the books simply revolved around justice being served to those who deserved harsh treatment, which was described in explicit detail."[14]

In the 1930s, the private eye genre was adopted wholeheartedly by American writers. The tough, stylish detective fiction of Dashiell Hammett, Jonathan Latimer, Erle Stanley Gardner and others explored the "mean streets" and corrupt underbelly of the United States. Their style of crime fiction came to be known as "hardboiled", which encompasses stories with similar attitudes concentrating not on detectives but gangsters, crooks, and other committers or victims of crimes. "Told in stark and sometimes elegant language through the unemotional eyes of new hero-detectives, these stories were an American phenomenon."[14]

In the late 1930s, Raymond Chandler updated the form with his private detective Philip Marlowe, who brought a more intimate voice to the detective than the more distanced "operatives report" style of Hammett's Continental Op stories. Despite struggling through the task of plotting a story, his cadenced dialogue and cryptic narrations were musical, evoking the dark alleys and tough thugs, rich women and powerful men about whom he wrote. Several feature and television movies have been made about the Philip Marlowe character. James Hadley Chase wrote a few novels with private eyes as the main hero, including Blonde's Requiem (1945), Lay Her Among the Lilies (1950), and Figure It Out for Yourself (1950). Heroes of these novels are typical private eyes very similar to Philip Marlowe.

Ross Macdonald, pseudonym of Kenneth Millar, updated the form again with his detective Lew Archer. Archer, like Hammett's fictional heroes, was a camera eye, with hardly any known past. "Turn Archer sideways, and he disappears," one reviewer wrote. Two of Macdonald's strengths were his use of psychology and his beautiful prose, which was full of imagery. Like other 'hardboiled' writers, Macdonald aimed to give an impression of realism in his work through violence, sex and confrontation. The 1966 movie Harper starring Paul Newman was based on the first Lew Archer story The Moving Target (1949). Newman reprised the role in The Drowning Pool in 1976.

Michael Collins, pseudonym of Dennis Lynds, is generally considered the author who led the form into the Modern Age. His PI, Dan Fortune, was consistently involved in the same sort of David-and-Goliath stories that Hammett, Chandler, and Macdonald wrote, but Collins took a sociological bent, exploring the meaning of his characters' places in society and the impact society had on people. Full of commentary and clipped prose, his books were more intimate than those of his predecessors, dramatizing that crime can happen in one's own living room.

The PI novel was a male-dominated field in which female authors seldom found publication until Marcia Muller, Sara Paretsky, and Sue Grafton were finally published in the late 1970s and early 1980s. Each author's detective, also female, was brainy and physical and could hold her own.[28] Their acceptance, and success, caused publishers to seek out other female authors.

A majority of detective stories follow the "whodunit" format. The events of the crime and the subsequent events of the investigation are presented so that the reader is only provided clues from which the identity of the perpetrator of the crime may be deduced. The solution is not revealed until the final pages of the book.

In an inverted detective story, the commission of the crime, and usually also the identity of the perpetrator, is shown or described at the beginning. The remainder of the story then describes the subsequent investigation. Instead, the "puzzle" presented to the reader is discovering the clues and evidence that the perpetrator left behind.

Many detective stories have police officers as the main characters. These stories may take a variety of forms, but many authors try to realistically depict the routine activities of a group of police officers who are frequently working on more than one case simultaneously. Some of these stories are whodunits; in others, the criminal is well known, and it is a case of getting enough evidence.

"Cozy mysteries" began in the late 20th century as a reinvention of the Golden Age whodunit; these novels generally shy away from violence and suspense and frequently feature female amateur detectives. Modern cozy mysteries are frequently, though not necessarily in either case, humorous and thematic (culinary mystery, animal mystery, quilting mystery, etc.)

Another subgenre of detective fiction is the serial killer mystery, which might be thought of as an outcropping of the police procedural. There are early mystery novels in which a police force attempts to contend with the type of criminal known in the 1920s as a homicidal maniac, such as a few of the early novels of Philip Macdonald and Ellery Queen's Cat of Many Tails. However, this sort of story became much more popular after the coining of the phrase "serial killer" in the 1970s and the publication of The Silence of the Lambs in 1988. These stories frequently show the activities of many members of a police force or government agency in their efforts to apprehend a killer who is selecting victims on some obscure basis. They are also often much more violent and suspenseful than other mysteries.

Even if they do not mean to, advertisers, reviewers, scholars and aficionados sometimes give away details or parts of the plot, and sometimes—for example in the case of Mickey Spillane's novel I, the Jury—even the solution. After the credits of Billy Wilder's film Witness for the Prosecution, the cinemagoers are asked not to talk to anyone about the plot so that future viewers will also be able to fully enjoy the unravelling of the mystery.

For series involving amateur detectives, their frequent encounters with crime often test the limits of plausibility. The character Miss Marple, for instance, dealt with an estimated two murders a year; De Andrea has described Marple's home town, the quiet little village of St. Mary Mead, as having "put on a pageant of human depravity rivaled only by that of Sodom and Gomorrah". Similarly, TV heroine Jessica Fletcher of Murder, She Wrote was confronted with bodies wherever she went, but most notably in her small hometown of Cabot Cove, Maine; The New York Times estimated that, by the end of the series' 12-year run, nearly 2% of the town's residents had been killed.[30] It is arguably more convincing if police, forensic experts or similar professionals are made the protagonist of a series of crime novels.

The television series Monk has often made fun of this implausible frequency. The main character, Adrian Monk, is frequently accused of being a "bad luck charm" and a "murder magnet" as the result of the frequency with which murder happens in his vicinity.

Likewise Kogoro Mori of the manga series Detective Conan got that kind of unflattering reputation. Although Mori is actually a private investigator with his own agency, the police never intentionally consult him as he stumbles from one crime scene to another.

The role and legitimacy of coincidence has frequently been the topic of heated arguments ever since Ronald A. Knox categorically stated that "no accident must ever help the detective" (Commandment No. 6 in his "Decalogue").

Technological progress has also rendered many plots implausible and antiquated. For example, the predominance of mobile phones, pagers, and PDAs has significantly altered the previously dangerous situations in which investigators traditionally might have found themselves. Some authors have not succeeded in adapting to the changes brought about by modern technology; others, such as Carl Hiaasen, have.[citation needed]

One tactic that avoids the issue of technology altogether is the historical detective genre. As global interconnectedness makes legitimate suspense more difficult to achieve, several writers—including Elizabeth Peters, P. C. Doherty, Steven Saylor, and Lindsey Davis—have eschewed fabricating convoluted plots in order to manufacture tension, instead opting to set their characters in some former period. Such a strategy forces the protagonist to rely on more inventive means of investigation, lacking as they do the technological tools available to modern detectives.

Several authors have attempted to set forth a sort of list of “Detective Commandments” for prospective authors of the genre.

According to "Twenty Rules for Writing Detective Stories," by Van Dine in 1928: "The detective story is a kind of intellectual game. It is more—it is a sporting event. And for the writing of detective stories there are very definite laws—unwritten, perhaps, but nonetheless binding; and every respectable and self-respecting concocter of literary mysteries lives up to them. Herewith, then, is a sort of credo, based partly on the practice of all the great writers of detective stories, and partly on the promptings of the honest author's inner conscience."[32]Ronald Knox wrote a set of Ten Commandments or Decalogue in 1929, see article on the Golden Age of Detective Fiction.

^Sims, Michael, ed. ‘’The Dead Witness: a connoisseur’s collection of Victorian detective stories’’, Bloomsbury, 2011: p2-3 Burton wrote the story for his own Philadelphia publication, Gentleman’s Magazine, which under a different owner later became the publication for which Poe wrote The Murders in the Rue Morgue. Poe worked for Burton, acting as his editor for some months in 1839, so may have known his story.

^Buckler, William. "Once a Week Under Samuel Lucas, 1859-65", PMLA, 67.7(1952): 924-941. In 1952, William Buckler identified the author of the novel as Charles Warren Adams and in 2011 American investigator Paul Collins found a number of lines of evidence that confirmed Buckler's initial claim.

^Julian Symons (1972), Bloody Murder: From the Detective Story to the Crime Novel. p. 51: "... there is no doubt that the first detective novel, preceding Collins and Gaboriau, was The Notting Hill Mystery.