19 September 2014

Sherlock Holmes & Software Engineering

In an earlier post I had mentioned "Pratyaksha Pramana" and "Anuman Pramana" and how these constitute the scientific method. And that "Shabda Pramana", contrary to what Justice Katju seems to think, cannot be part of the scientific method.

Sherlock’s Scientific Method

Very good illustrations of these are to be found in Arthur Conan Doyle’s, Sherlock Holmes mysteries. If you have not read them, I suggest you read a couple of them. If you have read them, it would have been a long time ago; I urge you to reread them.

The primary Pratyaksha Pramana is of course the crime. That is the phenomena for which a sequence of verifiable actions needs to be established.

Holmes then uses his acute powers of observation to establish a secondary set of Pratyaksha Pramana.  That enables him to deduce facts (Anuman Pramana) that appear incredible till Holmes describes his observations and the deductive steps. Holmes description of the deductive steps, to my mind, is equivalent to the presentation of a mathematical proof for peer review (not that Holmes would consider any of his interlocutors his peer).

Note it is not just “Pratyaksha Pramana” but acute powers of “Pratyaksha Pramana”. Acute observation is not sufficient. As Holmes says, “Having gathered these facts, Watson, I smoked several pipes over them, trying to separate those which were crucial from others which were merely incidental.” (The Crooked Man). Holmes emphatically expresses the primacy of data: “Data! Data! Data!” he cried impatiently, “I can’t make bricks without clay.” (From The Adventure of The Copper Beeches). If it is not relevant, it is not data. Needless to say, deciding what is relevant is error prone. The only way to reduce it is by regular practice of the scientific method.

Holmes’s “Anumana Pramana” are always subjected to test. In some cases the test consists of simply presenting the deductions to the person involved for their confirmation. In other cases Holmes sets up experiments. As for example, in the “The Adventure of the Beryl Coronet” he dons a disguise to get confirmatory evidence, in the form of the suspect’s used boots, from the suspect’s valet.

Why is Sherlock relevant to the practice of Software? Because, defect rectification is detective work; locating performance bottle-necks is detective work.

Cyber World Detective Work

“The Cuckoo's Egg” is the true story of how the author, Clifford Stoll, uncovered a cyber-attack by the KGB . The “Pratyaksha Pramana” was a 75 cent shortfall in the total billed computer time at a research facility! The Anuman Pramanas and the experiments (tests/traps) setup to verify those and ultimately catch the hackers makes for thrilling reading. 

Clifford Stoll is a scientist - an astronomer.

Dogs That Should Not Bark

The absence of "Pratyaksha Pramana" (call it "A-Pratyaksha Pramana") could also be valid observation. In the “Silver Blaze” the following conversation illustrates this:

Gregory (Scotland Yard detective): "Is there any other point to which you would wish to draw my attention?"
Holmes: "To the curious incident of the dog in the night-time."
Gregory: "The dog did nothing in the night-time."
Holmes: "That was the curious incident."

Assertions and Unit Tests are “dogs that should not bark”. Assertions are hypotheses (Anumana) as to what the internal state of the code should be (or should not be). Unit tests are an anumana (hypotheses) of what a unit of code will do for a given set of inputs. If an assertion dog barks it indicates something is not as expected. If they do not bark they provide "A-Pratyaksha Pramana" that the code behavior (anumana) is as expected – or to coin a words, as “anumana-ed”. However, it must be checked that the dogs can bark! The first step in Test Driven Development is to write a unit test that fails. Only then is functionality written that will silence the dog.


No comments: