XIV.3 When the way prevails in a system

子曰,邦有道,危言,危行。邦无道,危行,孙言。 ‘ — 论语,十四:三

The Master said, ‘When the Way prevails in the state, speak and act with perilous high-mindedness; when the Way does not prevail, act with perilous high-mindedness but speak with self-effacing diffidence.’ — Analects XIV.3 (Lau)

Confucius expresses not only a prudent guideline for ethical public service, but a principle for designing robust systems across diverse interfaces. Consider The Way prevailing in a trustable system: one you control, or one well established, open and of high quality. In these circumstances it is possible and desirable to do strict validation on subtly incorrect inputs, and to raise exceptions internally without fear of further system failure.

A bureaucracy is an information processing system of communicating agents. At the external endpoints of this system it can, through interfaces, have physical and social effects. Likewise, software is a bureaucracy of automatons. This is especially evident when the software system is decomposed into independently processing agents, as in concurrent or distributed systems. External effects depend on the system: a state may build a road, or put a man in jail; software may fly a plane, or a missile.

Such decoupled or distributed systems then have non-trivial needs for design of the communication protocol itself. This manifests, in traditional bureaucracy, as paper forms. Paper (or equivalent) is now seen as a technological pre-requisite for centralized state formation across larger geographic and demographic scales because it is an enabler for efficient central bureaucracy (eg Whitmore chapter on Dai Viet). In the time of Confucius the state ran on more unwieldy scrolls, but the problems of information flow in the state system are shared.

Facing similar problems of information design, Confucius gives similar advice to Jon Postel:

TCP implementations should follow a general principle of robustness: be conservative in what you do, be liberal in what you accept from others. RFC 761

Postel is perhaps more forgiving than Confucius, here. If a program must deal with badly formed inputs, The Way does not prevail in the system. If it tries too hard to be liberal in it’s interpretation of inputs, rather than logging an error, rejecting or ignoring the input, it is more prone to subversion. One could say the system does not act with perilous high-mindedness in maintaining its internal state.

The langsec group have a variation on the principle which bears even greater similarity: “Be definite about what you accept”. Log an error if you can, they might have added; else speak with self-effacing diffidence.

VIII.9 Made to follow a path

子日,民可使由之,不可使知之。– 论语 八:九

The Master said, ‘The common people can be made to follow a path but not to understand it.’ — Analects VIII.9 (Lau)

The Analects is addressed to students of government from an aristocratic class (君子, gentlemen). Confucian Software is addressed to software developers, and the fundamental analogy is that the audience is the same: Confucius instructing software developers on becoming gentlemen and sages.

So the differences between gentlemen and the common people are important. We should distinguish the gentleman (who is educated) from the people (who are not) and the small man (小人) who has no understanding or respect. (See Analects XVI:1.)

At first glance this passage is Confucius at his most snobbish and feudal. The people, or the common people (民), can only be driven down a path and are devoid of thought and understanding. This is the same word now used in the People’s Republic of China (中华人民共和国), the word democracy (民主) or all of Sun Yat-sen’s (孙中山) three principles of the people (三民主义). So it can be rather off putting for we moderns.

Indeed, it sounds more like the brutally effective carrot and stick of Lord Shang (商鞅) and the Legalists (法家) than gentle old teacher Kongzi. Passages like this show how the Han dynasty could create the political philosophy of Imperial Confucianism (as John King Fairbank terms it) – the fusion of a Confucian public morality with the real-politikal techniques of Legalism to run the sausage factory of government. The Legalists found just how far you could push realpolitik without public morality when the common people revolted and overthrew the short-lived Qin dynasty (秦朝), which established the Chinese empire, but could not make it endure.

The relationship of the developer to her users via code is that of the scholar official to the people via the bureaucracy. It is also isomorphic to the GUI model view controller pattern.

People Scholar Bureaucracy – Model View Controller

Users walk a path laid out by the code, and beyond a certain point, can take no other.

The code too can be made to follow a path, when we constrain and verify that a path is followed. This is the purpose of testing, to ensure deterministic repeatability. Without testing, there is no engineered path. There is just walking.

When we anthropomorphize software by describing it as thinking, it means we do not have sufficient control on its internals and environment. (By calling the people code we are automatomorphising people as much as we are anthropomorphizing code.) Code cannot think. Once thinking creatures are built on code we should no longer deal with them as code.

Can users be made to think (know, understand)? Ah, you laugh! Feudalism is not so dead after all.

Code certainly cannot be made to think. Nothing can be made to think. And this is also the more generous interpretation of Confucius’ intent. You cannot make the common people  understand a path, you can only lead them to understanding. The meaning of a software system is generated by this interaction.

Confucian Software For The Impatient

For those who have found themselves intrigued by the conceptual parallels between a group of underemployed, bookish Han Chinese civil servants from two and a half thousand years ago and the electrically engineered plumbing of our contemporary information age, but find my treatment of it rather longwinded, not to mention sullied somewhat by a Dickensian tendency to long, single-paragraph sentences with interstitial tangents, this short presentation by nein geist on Confucian Philosophy in Software Design may be more to taste.

XIII.3 Name Oriented Software Development

子路日:卫君待子而为政,子将奚先.子日:必也正名乎. 子路日:有是哉!子之迂也.奚其正.子日:野哉由也.君子于其所不知.蓋阙如也.名不正,则言不顺.言不顺,则事不成.事不成,则礼乐不兴.礼乐不兴,则刑罚不中.刑罚不中,则民无所措手足.故君子名知必可言也.言之必可行也.君子于其言,无所苟而已矣. — 论语 十三:三

Tzu-lu said, ‘If the Lord of Wei left the administration (cheng) of his state to you, what would you put first?’ The Master said, ‘If something has to be put first, it is, perhaps, the rectification (cheng) of names.’ Tzu-lu said, ‘Is that so? What a roundabout way you take! Why bring rectification in at all?’ The Master said, ‘Yu, how boorish you are. Where a gentleman is ignorant, one would expect him not to offer any opinion. When names are not correct, what is said will not sound reasonable; when what is said does not sound reasonable, affairs will not culminate in success; when affairs do not culminate in success, rites and music will not flourish; when rites and music do not flourish, punishments will not fit the crimes; when punishments do not fit the crimes, the common people will not know where to put hand and foot. Thus when the gentleman names something, the name is sure to be usable in speech, and when he says something this is sure to be practicable. The thing about the gentleman is that he is anything but casual where speech is concerned.’ — Analects XIII.3 (Lau)

If something has to be put first in programming, it is, perhaps, the rectification of names. Names are what place the system and the not-system in the same reality. They are the bridge between the externalized machine without use and the internalized emotion without expression.

What in Confucian philsophy we call the rectification of names we can in Confucian software call Name Oriented Software Development. This does not yet exist, but it can be defined simply. Name Oriented Software Development uses a toolset that promotes the continuous rectification of names across all the interstices between natural languages and machine languages in the system.

The nominalist toolset should span package, class, variable and method names. It should span library and project names. It should cover layers of code around the core system, including message protocol definitions and protocol dictionaries, configuration entities, unit and performance tests, and run scripts. The aim in managing machine facing names is to enforce consistency and coherence of names while making precision in naming, including type restriction, easy. The same name appearing in different machine-facing contexts, eg a message protocol field in a script and a Java class, should be linked in an automated and machine verified way. This might at first seem to make the internal technical dialect (namespace, one could say, if it were not taken) too rigid. This is not the intent, and if we look at the rename variable refactoring, not its effect in smaller scopes. It is because we can execute refactorings in a reliable, automatic way that it becomes viable as a low-risk change. This is the same across the entire internal technical dialect – enforced formal consistency allows mutability to be low risk.

By contrast, the aim in managing people facing names is to allow a consensus jargon to emerge backed by a literature of interaction and aspiration which is still moored to the technical reality of the system as it exists. This covers specifications, use cases, test documents (even and especially automated acceptance tests), application messages or labels for users or external parties, internationalization, log messages (ie, a UI for support) support and developer faqs, and user manuals and documentation. Changes to this shared understanding should be reflected as immediately as possible and not tied to a long software release cycle. A label, for example, is essentially a piece of simple key-mapped static data; changes to it can therefore be routine and implicit. When treating this sort of text as static data, it is essential to keep it automatically linked to the running widgets themselves – otherwise it is merely the domain of style guides and moral exhortation. A true dialect is owned by a community – a folksonomy – so the entire community must be able to use and contribute to it. The editors for these documents should be as broad as possible within organisational constraints. Where editing constraints exist (organisational not technical), annotation on these documents should be easy. Cross referencing within the docset and outside it to external sources of expertise (for instance on domain jargon) should also be easy to add and maintain.

Or, via Wittgenstein, Tractatus 7: Whereof one cannot speak clearly, one must damn well link to a wikipedia entry.

This approach owes more than a little to Knuth’s Literate Programming. A distinction is that instead of putting documentation with source code in a single artifact to be owned by a single philosopher-developer auteur, it puts editable, often executable content in the hands of a community of expertise.

Historically, the Confucians became increasingly sophisticated in their theory of names. I know of no record of Confucius addressing names changing over time, apart from a general openness to political reform (Analects IX.3). Indeed, as old Kongzi was often conservative, the quote above might reasonably be taken to advocate reverting to old names now in disuse. Xun Zi (荀子), who lived in the century after Confucius and was one of his major intellectual heirs, saw fit to reuse the Mohist (墨家) theory of names.

单足以喻则单,单不足以喻则兼; […] 名无固宜,约之以命,约定俗成谓之宜,异于约则谓之不宜。名无固实,约之以命实,约定俗成,谓之实名。名有固善,径易而不拂,谓之善名 — 荀子 – 正名 6-8

If a single name is enough to communicate, make it single; if not, combine. […] Names have no inherent appropriateness, we name by convention; when the convention is fixed and the custom established, we call them appropriate, and what differs from the convention we call inappropriate. No object belongs inherently to a name, we name by convention, and when the convention is fixed and the custom established, we call it the object’s name. Names do have inherent goodness; when straightforward, easy and not inconsistent, we call them good names. — Xun Zi – Rectification of Names 6-8 , AC Graham translation

AC Graham’s use of the word “combine” (兼) above is in the sense of “compound”. This is the term the Stanford Encyclopedia of Philosophy uses in preference. That entry points out Xunzi’s concern with names is also in rebuttal to the paradoxes of the Chinese sophists. Furthermore, Xunzi is rather more open to mutability and the pragmatic construction of language from a vernacular folksonomy. (The term 俗成, translated as convention, includes 俗 which now spans meanings including custom and vulgar.)

Computer science launched itself out of the western analytical tradition, though. A sometime description and criticism of Object Oriented design is that it is reheated Platonism. See, e.g., blogs by Vlad Tarko and Richard Farrar. ((Should the frequent light analogical treatment of Platonism and software sound a note of alarm for this very project? Perhaps. But there is heavier academic firepower behind us as well. Are we not grappling with code, which Berry and Pawlik call the defining discourse of our postmodernity? In an article that has more code metaphors than a house full of crack-addled Java-monkeys at teatime.))

The platonic analogy has legs. We do construct a parallel world of sorts in code. It is also revealing to think of classes as ideal representations of some external physical element. Isn’t that why we often fail as programmers? We critique the world for being less perfect than our ideal programs, for failing to match up to their strict conditions, for making them ugly, for crashing them. Code, and OO, can have a kind of brittleness that happens when we stop thinking of software as a model of the world and start thinking of it as the true world. We fit our shape to the name.

My suggestion is not to stop doing taxonomy – we could not navigate the world and construct alternative worlds out of software without it. We couldn’t even speak without it. Instead, we should use Xunzi’s advice and fit our names to the shape. We name by convention. We continually rectify names. If a single name is enough to communicate, make it single. If not, combine.

‘RenameClass’ is the most powerful refactoring. — Michael Feathers

X.18 When his lord gave him a gift of a live animal, he invariably reared it

君赐食,必正席先尝之。君赐腥,必熟而荐之。君赐生,必畜之侍食于君。君祭,先饭。– 论语,十:十三

When his lord gave a gift of cooked food, the first thing he invariably did was to taste it after having adjusted his mat. When his lord gave him a gift of uncooked food, he invariably cooked it and offered it to the ancestors. When his lord gave him a gift of a live animal, he invariably reared it. At the table of his lord, when his lord had made an offering before the meal he invariably started with the rice first. — Analects X.18 (Lau)

We must respect working systems. Working systems are living systems and have a life that should be respected. In these early years of software, being handed a living system is often being handed a legacy system. And legacy systems are off-putting to some of the technical senses. They offend our inner fashion designer with their unfashionableness. They offend our inner engineer with their inelegance, or our inner scientist with their reliance on a dead paradigm.

Or they might simply offend our inner creator, because an adopted system is not our system: we have fallen for the greenfield myth. There is no true greenfield in contemporary software, and that is a mark of our success. In Java: you started a new eclipse project for this; it depends on fifty other libraries. You wrote your own library set; they depend on Java standard libraries and the virtual machine. You wrote your own compiler or interpreter: they depend on the operating system. You wrote your own operating system: it depends on the hardware. (But you didn’t really write your own operating system, did you? Even Linus Torvalds needed the GNU toolset.)

And even if you doublethink the greenfield in your mind into existence, you make shiny new eclipse project a tabula rasa, you will leave your desk at the end of that first day. And on the second day, when you unlock the screen and return to your code, you will be doing software maintenance.

When your client, or your corporate lord gives you the gift of a live system, what is your response? The ceremony exists because the logic of the organisation brought it into being, and this is to be respected (恕). It will probably need to change, because to live is to change. Perhaps it needs to merge with some other system, or needs to do its function immediately instead of overnight. This is to the good. When your lord gives you a gift of a live animal, you invariably rear it.