Tuesday, October 19, 2010

Android and Contraption

Back in July I wrote briefly about Cascada, my little project to move my software developed as part of my Diminuto project from the AT91RM9200-EK board (which uses the Atmel AT91 ARM9 processor) to the smaller, much cheaper, and more powerful BeagleBoard (which uses the TI OMAP 3530 ARM11 processor) with the TinCanTools Zippy2 expansion board. Cascada turned out to be so straightforward, I was a little disappointed. I didn't really feel like I'd gotten the learning experience I'd expected.

So I evolved the project into Contraption, where I run the "Rowboat" port of Android, the Google mobile device environment, to the BeagleBoard. This would have been a no-brainer too had I not insisted on getting the Zippy2 Ethernet port working. That required I reverse engineer the configurations of the Angstrom U-Boot bootloader and Linux kernel for the BeagleBoard that support the Zippy2, use what I learned to build the Linux that come with Android (which is slightly different), substitute in the U-Boot that initializes the Zippy2, and get the whole mess running on my hardware.

A few evenings of head scratching, and the next thing you know I'm displaying my blog on the Android browser.

Contraption

Scattered around my tiny lab bench is (roughly left to right) a WiFi to Ethernet bridge (which will play a role in a later article), the tiny BeagleBoard, an Ethernet switch, a BDI3000 JTAG debugger (mostly unnecessary), a fan (also mostly unnecessary except to keep me cool), and a powered USB hub. The keyboard and mouse on the left are connected to an ancient ThinkPad I use as a window and TFTP server, and the smaller keyboard and mouse on the right are connected to the BeagleBoard. Below is the Android home screen running on the BeagleBoard.

Google Android ("Rowboat") on BeagleBoard

Why Android? Lots of reasons, but the most compelling was that I had come across a technical report written by some students at the University of Applied Sciences Northwestern Switzerland about using Android in industrial automation. I'm all about frameworks for real-time software design, and this was right up my alley. It will also be an excuse to brush up my Java skills and learn how to develop in the Android environment.

Somewhat ironically, since I've spent the past nearly fifteen years working for one Bell Labs spin-off or another, my interest in Android is not really related to mobile phones. I have a whole other project in mind. But that will have to wait for a future article.

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.