Java Authors: Sharon Barkai, Elizabeth White, Liz McMillan, Pat Romanski, Kevin Benedict

RSS Feed Item

Tennent's Correspondence Principle

Certain elements in the Java and JavaScript communities have been buzzing about Tennent's Correspondence Principle. I have heard it described as the ability to replace an expression with a function, so that


means the same thing as

(function () { return expression; })()

There are some things that can't be enclosed that way, such as return statements and break statements, which the advocates of Tennent's Correspondence Principle (or TCP) claim is a symptom of a bad smell. Yow! Language design is already difficult enough without having to cope with olfactory hallucinations. So to better understand the problem, I bought a copy of Tennent's 1981 book, Principles of Programming Languages.

It turns out that the Correspondence Principle is descriptive, not prescriptive. He uses it to analyze the (by now forgotten) Pascal programming language, showing a correspondence between variable definitions and procedure parameters. Tennent does not identify the lack of correspondence of return statements as a problem.

He does seem to have some specific notions of good programming language design, however. For example,

Many existing languages only managed to combine countless "features" into a jumble that is neither easy to implement nor a pleasure to use.

It is amazing how little has changed since 1981. He also has warnings about side effecting features such as getters and setters:

Side effects are often confusing to program readers because they are unexpected: the familiar expressions of conventional arithmetic and algebra do not have side effects.

Read the original blog entry...