It's a landmark detective novel given the historical context and relevance when the novel was published. It was published in the US before WWII and at the stage of the 'Great Depression.' If Dashiell Hammett made Sam Spade a churchgoer every Sunday and faithful follower of the ten commandments (and drinks only milk or fruit juice) would only made him a very boring detective. The original story was published serially in a magazine that caters to adult reader and Sam Spade's complexity in the story provide depth to his character, his immorality made him realistic. His detective work is still, the center of the story and not his twisted morality.
Sir Arthur Conan Doyle made Sherlock Holmes an occasional user of cocaine and opium (it wasnt illegal at that time) to induce the same level of thinking with his enemies to solve the mystery. But Doyle never suggested that his readers must also try opium.