Friday, June 16, 2006

Practical Programming

The first question that comes to the mind of the inquisitive is – What is a program? Put simply, a program is merely a defined sequence of instructions that must be followed to perform a certain task. The word 'must' makes it obvious there is to be no deviation from the sequence defined; even an automaton with no more intelligence than the ability to follow the sequence may achieve the expected result. Of course, if the sequence may throw some unexpected situations as a result of one or more instruction intelligence may then be required. The may is subject to the degree of customization provided to deal with the unexpected. The simplest way, obviously, is to deal with all unexpected situations with a single yardstick.

Thus if the task is 'clean'; the sequence of instructions may be

a) Start
b) Identify Dusty
c) Remove Dust
d) Repeat from b) until no more surface Dusty
e) Stop

Obviously, this is a rudimentary sequence. As the art of programming evolves, we find it is not necessary to have the instructions repeated ad infinitum. It is enough to define the instructions independently and only provide the necessary input with each call. But this still has a drawback; the step c) may vary depending upon the input provided. For instance – removal of dust from a glass surface is best aided by application of some fluid. But removing dust from, say, a computer motherboard with a fluid is a definite no-no. Therefore we realize while the task 'clean' is a generic description, the actual cleaning is specific and depends upon what is to be cleaned.

Anthropologically, the caste system is not very different. The origins of the Caste system are shrouded by mists of time, and beliefs. What we do know for certain about the Caste system, as identified by the Aryans in India is that there were 4 primary castes –

Kshatria/Kshatriya/Warrior,

I wonder whether the term Kshatria may not simply mean kshatra, chattra/umbrella as we use the term in present day hindi. The purpose of an umbrella is to provide shelter/respite from the elements. The Kshatria therefore becomes the caste that holds the umbrella[for the members of the community, where the term community refers to all regardless of caste].
Brahmana/Priest/Intelligentsia,

Vaishya/Merchant,

Shudra/Menial Tasks.

Similarly, I wonder whether the term Shudra may not be related to the term 'shudh/shuddh/purify', as we use the term in the present day. The term itself is Sanskrit, and means Purify. While the suffix 'ra' is unknown to me, i wonder whether the term may not then refer to the people who bore the responsibility of keeping the habitat spic-and-span, so to speak... obviously a far cry from the apparently derogatory 'untouchable'.

We therefore have the caste system as being task/function oriented; not a very original idea, but I choose to believe it.

Why did the ancients consider it worthwhile to divide the society so? Did they not realize that such a divided society might not survive? They certainly did, and if we are to believe even the most conservative of estimates the society, as split into castes, has survived for atleast a millenium. The divisions obviously served a purpose which we do not seem to recognize today.

To a programmer, the caste system is a classic example of object oriented programming theory. OOP is built upon the properties

i. Encapsulation/Confinement of knowledge
ii. Generalization and specialization
iii. Inheritance/Propagation of knowledge through heirarchy

In object oriented programming OOP, in short] a program is comprised of a number of objects. Each object is based upon a defined template, with properties and responsibility assigned. Such template is referred to as a 'class'.
Thus, for instance the above sequence of instructions may be represented as a class with the property and responsibility as mentioned below

class Cleaner Responsibility: Identify Dirty, Perform Cleaning Uses: Cleaning instrument
The advantage of such a classification is the knowledge is then encapsulated or confined. Thus the knowledge of cleaning is now the responsibility of Cleaner. The question is – why confine the knowledge? The answer – because encapsulation helps prevent misuse. Imagine what may happen if one intended to dry-clean the control panel in a nuclear submarine!

Jokes apart, a more practical reason to encapsulate knowledge is this - Delegation of a task frees the delegator to undertake other tasks. Thus in a society comprised of various castes, as mentioned earlier, a warrior need not worry himself overly about living in unsanitary surroundings because it would be handled by the section of the society responsible for that task. Similarly, the menial labourer would not need to concern himself with things other than his own task because it would be handled by the sections of society responsible for those tasks. Commerce handled by the Merchants, planning for the future of the society by the intelligentsia, protection of the society by the warriors, and so on.

Moving on to the twin properties of Generalization & Specialization, the task of cleaning itself is a very broad definition. For instance, cleaning a glass plate is quite different from dry cleaning a silk cloth. If the one method is applied to the other, it may not have quite the expected result. The task of cleaning may be further narrowed down, to improve efficiency.

We see similarities applied in everyday life. A bank may be a good example; when one enters a bank the obvious task has something to do with money... a loan, or a payment, or a withdrawal, or a deposit. Again, each of these may have their own hidden subtleties. Ideally, we do not need to know more about what goes on behind the closed doors to be able to use the facilities better.


OOP has another advantage; a property termed as Inheritance. By inheriting from an existing class, the knowledge encapsulated by the original class is made available to the inherited/child class without significant additional effort required. The parallel, as applied to the Caste System is apt.

The more one is exposed to a profession from childhood days, the more one inculcates. There is the argument that the knowledge gained by a generation may be passed on to subsequent generations by means of writing/pictorial representation and so forth. Documentation is useful. The practice of documentation helps to convey some portion of the knowledge to newcombers in the profession ... we see that frequently in the field of programming, perhaps in all professions nowadays. Reading conveys part of an experience. Listening to the person who experienced it, with all the vocal inflections and facial expressions is something different altogether. However one has to live an experience to brand it into memory.

There is, of course, the drawback that such hereditary knowledge may result in stagnation. I concede the point with the example of what the Caste system is, as it exists as we see it today. We do not know, with any degree of certainty, the origin and the rationale, and yet it persists mostly because it 'is traditional'.

No comments: