Wednesday, October 06, 2010

Design Patterns and the Hylaean Theoric World

Neal Stephenson's novel Anathem is a 980 page discourse on philosophy, mathematics, and science disguised as a damn good science fiction novel. The philosophers, mathematicians, and scientists in his novel have the concept of the Hylean Theoric World (HTW), a realm in which the immutable truths of their universe and, as it turns out, ours, can be found. This is their version of our Platonic Idealism: the fact that the number three is prime is true no matter where you live, in what era you live in , and what your laws of nature may be. The concept exists independent of everything else, as if it inhabited its own reality.

One of the more controversial ideas of HTW (and of Platonic Idealism) is that that independent reality is a real place. But while it's hard to argue with the fact that three is prime, it's a little tougher to convince people that there is an alternate universe where the fact that three is prime originates. I can appreciate, however, that point of view.

That's why for decades, scientists and science fiction writers pondering how to communicate with intellects on another planet have assumed that the starting point for any such dialogue would be mathematics. You would establish a symbolism and nomenclature to represent stuff that you knew your opposite number on the other planet would understand, regardless of the fact that they might have tentacles, breath methane, and use smell as their principle sense organ.

Mathematics would be the root of a common inter-species language, but perhaps not science, at least not all science. There is some evidence, still quite controversial, that the laws of nature might not be exactly the same throughout the universe. So you run the risk of the the tentacled folk pondering your latest missive and saying "These crazy aliens, just when we thought we understood them, they go on about this Fine Structure Constant as if it were constant! We have clearly misunderstood something." The good news, though, is that anyone with whom we are likely to have a dialogue approaching anything like real-time would have to be close enough to us that this isn't going to be an issue.

It's easy to see how mathematics would live firmly in the Hylaen Theoric World, even if all of chemistry and physics might not. What else?

How about design patterns? One of the struggles authors of design pattern books have is how to represent design patterns. You have to appreciate the problem here, because while design patterns are not tied to a specific language, they are often much more easily implemented in one language than another. (I probably did something like dependency injection even back when I used FORTRAN IV, but I have no idea how I might have done it. I remember frequently resorting to writing subroutines for FORTRAN in assembler back in those days, because assembler had pointers.)

The classic Gang of Four design pattern book uses a mixture of text, diagrams, and source code in Smalltalk and C++. Some design patterns books have been published in separate C++ and Java editions. Donald Knuth invented his own assembler-like language just to tackle the same issue in his classic The Art of Computer Programming series of books on algorithms.

But the design patterns themselves really are language-agnostic. So I claim they are examples of Platonic Ideals, and live in the HTW. If we could get past the representation issue, design patterns would be another way to communicate with our tentacled colleagues.

Many design patterns are not obvious, and understanding them and successfully applying them carries enormous potential consequences. Sure, the tentacled ones would nod each of their heads and appreciate our explanation of their well known adapter, facade, and proxy patterns. But when we beam more complicated ideas like map-reduce at them, their tentacles might start shaking as they understood the implications of a powerful distributed computing architecture. We could, perhaps inadvertently, change their world. Or vice versa: they could change ours by transmitting a meme so powerful that it captured our intellects and imaginations.

The other day I listened to some of my colleagues try to define what they meant by "elegant code". Here is how I have defined it in the past: elegant code is that which reveals a higher truth. But it wasn't until I was reading Anathem that I realized that what I was really saying was elegant code is that which reveals a Platonic Ideal pattern that was previously unknown to me, one that offers me a glimpse into the reality that is the Hylaen Theoric World. One that I am totally going to appropriate and use myself.

Because when you are an engineer, Rule One is: steal all the good ideas.

No comments: