Lockhart's Lament

Lockhart seems to agree with Dijkstra, that problem solving can be taught. But my mind fixed on something else in the paper. The much criticised geometry proofs mentioned on page 21 looks very much like programming. Why not use Haskell notation? Or even better, Coq? The proofs could be type checked and evaluated automatically. The students would learn to program at the same time they were learning geometry. They are learning to program now as well, they just don't know it, and would probably have difficulties to apply their newly gained knowledge in programming, due to the special notation used.

The programming approach would also allow the students to create theorems of their own to be used in future proofs, building a library of geometry as they go.

Even though I agree with Lockhart that problem solving should be emphasized instead of mechanical application of rules, by not using a formal system, he relies too much on human intuition in the proofs created. The informal proof on page 21-22 is elegant, but relies on the intuitive understanding of rotation and that rectangles have diagonals of equal length alternatively that rectangles have corners with right angles (both can not be the definition of a rectangle).


Connect to Internet with a Bluetooth 3G Phone

There are many tutorials available that describe how to connect to Internet using a 3G phone with bluetooth, but none of them worked for me. I had to use a combination of several sources. This is what worked.

I want to connect to Internet with my Asus Eee PC 901 using my SonyEricsson W880i. The operator I use is Tele2 in Sweden. I have installed Ubuntu Eee on the netbook.

First I used Blueman to configure the bluetooth connection using this tutorial. This should result in a /etc/bluetooth/rfcomm.conf looking something like this:

rfcomm0 {
bind yes;
device AA:BB:CC:DD:EE:FF;
channel 2;
comment "W880i";

The device is the mac address of your phone and the channel is the same as your phone's Dial-up Networking channel. You can find out your channel using Properties in Blueman. The Serial Port channel also worked for me.

Then I wrote the following in /etc/wvdial.conf, found in this tutorial.

[Dialer defaults]
Modem = /dev/rfcomm0

[Dialer tele2]
Modem = /dev/rfcomm0
Baud = 115200
Init2 = AT+CGDCONT=1,"IP","internet.tele2.se"
Phone = *99#
Username = *
Password = *
New PPPD = yes
Auto DNS = 1

I start the network with the following command.

wvdial tele2


Language and Abstraction

'Hell, one of the lessons of Structure and Interpretation of Computer Programs is that a "language" is a natural way of abstraction...', says ivdkleyn on Reddit. I agree and make an even stronger statement. Language is the only way of abstraction.


Reading Fielding - Software Architecture

In the first chapter of his dissertation Architectural Styles and
the Design of Network-based Software Architectures
, Roy T. Fielding defines software architecture.

A software architecture is an abstraction of the run-time elements of a software system during some phase of its operation.
A software architecture is defined by a configuration of architectural elements...

From this I draw the conclusion that a software architecture is a configuration of abstract run-time elements. Abstraction is the process of removing irrelevant details. A software system can be abstracted in many ways, depending on what you want to show. This means that a software system has many architectures. I must object to this definition. To say that a building has many architectures just sounds strange. Perhaps what is meant is that the design of a building is influenced by many architectural concepts. Despite this, the building only has one architecture, its own.

My definition of software architecture adheres more to the traditional meaning of architecture as the documentation for a specific software system as a whole. Fielding makes software architecture synonymous with configuration, which is just one of many abstractions of the whole system. This also have consequences for his understanding of the term architectural view. In Fielding's definition, it is the configuration that can be viewed from different angles, when it should have been the architecture as a whole, with the configuration as one view.

More interesting is Fielding's definition of architectural style.

An architectural style is a coordinated set of architectural constraints that restricts the roles/features of architectural elements and the allowed relationships among those elements within any architecture that conforms to that style.

Styles exist to make it easier "to directly compare architectures for different types of systems". This is a good definition that I can agree with, except that I would have written "to directly compare architectures for different systems", to be more true to my definition of software architecture. But this is a minor complaint. It is worth noting that Fielding does not use the term pattern due to its altered meaning within OOP as compared to Alexander's original definition.

When I look at the definitions as a whole, I get the feeling that Fielding, in his desire to define architectural style, has pulled the definitions of software architecture, configuration and style together, almost making them the same. It would have been better to differentiate them more, making each of them clearer as a consequence.

Lets proceed with connectors.

A connector is an abstract mechanism that mediates communication, coordination, or cooperation among components.
Internally, a connector may consist of a subsystem of components that transform the data for transfer, perform the transfer, and then reverse the transformation for delivery.

I don't use connectors when I describe my own architectures. I think it is better to connect components directly with a use relation. If transformations are necessary, they are better handled by an additional component, implementing languages for the communicating components to use.

Finally I want to say something about data. Lets see how Fielding defines them.

A datum is an element of information that is transferred from a component, or received by a component, via a connector.

I agree with Fielding that data is important. But I choose to include them in the definition and design of languages, subsequently used and implemented by components. I get a feeling that he likes the notion of data being transmitted over connectors because this closely mimics his own main interest, the design of network-based software architectures.

Yes, behind every component and connector there can be a large architecture that has been abstracted away. In this sense Fielding is correct when he talks about "the many architectures within a system". But this definition is not useful when analyzing the architecture of a system, precisely because all the uninteresting architectures have been abstracted away.

In one of his blog posts, Fielding says "Compare that to the Atom architecture within my blog, which consists of just the externally observable behavioral abstraction." In my view, externally observable behavior is a language or interface, not an architecture. Perhaps this is not what he meant, but it is easy to draw that conclusion.


Robotics - Motor Driver

As a hobby project, I build an autonomous LEGO robot controlled by an Arduino Nano with assorted sensors and actuators.

I use two electrical motors powered by a 7,2V racing accumulator pack. To control the direction of and power to the motors, I use two Allegro UND2916B motor drivers in parallel, one soldered on top of the other. See the image below for the complete circuit layout.

Unfortunately, there is an error in the schema. To correct it, the Arduino Nano connections should be shifted one step down, so D8 connects to D7 instead, D7 to D6, and so on.

I do not use the PWM capabilities in the 2916. Instead I use the PWM outputs on the Arduino.

In the Arduino Development Environment, I define the meaning of the different signals.
byte leftDirectionPin = 7;
byte leftSpeedPin = 6;
byte rightSpeedPin = 5;
byte rightDirectionPin = 4;


Robotics - Telemetry

As a hobby project, I build an autonomous LEGO robot controlled by an Arduino Nano with assorted sensors and actuators.

Using a simple radio link between the robot and a PC, I can monitor the current state of the software running on the Arduino.

The radio link is based on the circuits TX433 and RX433 from Velleman. The receiver is connected to the PC with a TTL-232R cable from FTDI. See the image below for the complete circuit layout.

To transmit data from the Arduino, I open the serial link and write tagged data to it.


The various tags and values are collected and displayed by a Processing application on the PC.
import processing.serial.*;

String tty = "/dev/ttyUSB0";
Hashtable data;
Serial port;
PFont font;

void setup() {
size(300, 600);

data = new Hashtable();
port = new Serial(this, tty, 4800);
font = loadFont("Dialog.plain-14.vlw");
fill(0, 0, 0);

void draw() {

while (port.available() > 0) {
String line = port.readStringUntil(10);
int pos = 0;
if (line != null &&
(pos = line.indexOf(":")) > 0 &&
pos < 30) {
data.put(line.substring(0, pos+1), line.substring(pos+1));
data.put("time:", "" + hour() + "." + minute() + "." + second());

int y = 20;
for (Enumeration e = data.keys() ; e.hasMoreElements() ;) {
String key = e.nextElement().toString();
String value = data.get(key).toString();
text(key, 4, y);
text(value, 104, y);
y += 20;

You need to create the font Dialog.plain-14 in Processing GUI for the program to work. The end result looks something like this.

The time parameter is there to show when the last message was received.


Components, Software Architecture and Product Structure, part II

In the first part about Components, Software Architecture and Product Structures, I did not go into the details when a natural component defined as a binary sequence should be an explicit part of the software architecture. I will do it now.

First I want to clarify that all natural components in the software system are part of the architecture, the question is if they can stand on their own or must be part of a bigger collection of components.

A good software architecture requires that its components are reusable. This is achieved when the components implement well defined languages. Languages are the foundation for reusability.

When a natural component is not independent enough to implement a language by itself, it is put in a collection of components, that together implement a language. This can for example be a collection of classes in an object oriented language that implement an API. Single classes are often not reusable by themselves, because they have too many dependencies to other classes in the API. It is the entire API and its implementation that is reusable. Therefore, it is the API as a whole that is interesting to show in the software architecture.


Language Design

Unless you are a programmer that only follows specifications written by others when you program, you have designed several languages already, even if you didn't think of it that way. "But I haven't written any programming languages," you say. "I don't even know how an interpreter or compiler works." But that is not what I mean. Let me explain.

Whenever you work with your computer, you are using one or more languages. Languages define the way you as a user interact with components in the computer, and how components interact with each other. "I have actually implemented a couple of user interfaces. Is that what you mean?" Yes. "And one of my programs could be configured with a property file. Do you mean the property file is a language too?" Almost. I would say the property file is written in a language of your design, but the property file itself is a component in the software architecture, not a language. The property language is also implemented by the application reading the file. "But I was only using the standard Java property file format. I didn't design anything." Yes you did. You choose the parameters and what impact they will have on the application. Your property language is, as you correctly point out, an extension of the standard Java property files, but also a unique language. It would be impossible to interpret the meaning of your properties with only the Java property file definition as a reference.

When designing a language, I start to think about what I want to be able to do with the language. I write some statements a potential user would write, or think through a couple of use cases. At the same time, I start to define the nouns and verbs in the language with a model of the terminology used. The language then evolves to handle all requirements from the initial user. I always have an initial user, or I would not design the language at all. The hard part is then to make the language useful for others. If I only have one user, I will have to guess where to generalize and when to specialize. I definitely want to be as specific as possible, or the users will find the language useless for its purpose.

Then, if not earlier, comes the question if the language should be a standalone language with its own syntax and semantics or if it should extend some existing language. In the latter case it could be a programming language API, an XML schema, a GUI, a BEEP protocol, and so on. Another decision is if the language should be defined using a formal language like IDL or ASN.1, or if the language should have an informal description only. In the extreme case, a new formal language description language is developed in parallel. Another popular way to describe the language is to write an interpreter for it using itself, but this only work for Turing complete languages, and probably needs an informal description as well, for anyone to understand it.

The conclusion is that whenever you write a program on your computer, you implement some language at the same time. It doesn't have to be a state of the art generic programming language with the latest type theory, even a simple graphical user interface counts. If you always know which language you are implementing, you have come a long way towards being a successful programmer.

And now something to think about. If the property file is a component, which language does it implement? "Sigh, I don't know. Wait! Don't tell me. It is extending one of my other languages, right?" Right.


Components, Software Architecture and Product Structure

I shall begin with some basic concepts that are useful when discussing software architecture and the software development process.

Sequences of binary data are the foundation of software systems. These sequences form the natural components in the software architecture. The binary data are structured according to some language definition and, when interpreted, will give rise to a specific behavior. We say the component uses a given language to implement a new language, which is then available for some other component to use. Components are usually stored in files, but can also be volatile streams.

Note that a component never can do anything by itself. It must always be interpreted by another component which implements the language the former uses. It may seem we are building a castle in the air, or have turtles all the way down, but this time we are lucky. At the bottom is the microprocessor, a component which connects the logical structure of the software architecture to reality, which is what we care about for all practical purposes.

I must now clarify that I do not use the term software component as described in this Wikipedia article, or any other framework for connecting modules together. I mean that any meaningful binary sequence is a software component. It can be a text file, an executable, a network packet, an office document, a source file, a script, an mp3 file, a divx movie, user interaction, and so on.

The languages that connect components are what computing is all about. They are purely abstract constructs that alone define what can be done to reality through the microprocessor. A language can be a communication protocol, a programming language, a video or audio format, an instruction set to a microprocessor, an office document file format, and so on. It is common for languages to be extensions of other languages, for example programming language APIs (AWT/Java), XML schemas (RDF/XML) or protocol layers (TCP/IP).

I don't think I will ever catch up with the state of the art in language theory as it is frequently discussed on Lambda the Ultimate. But I will try, and the obvious read for the beginner is of course Structure and Interpretation of Computer Programs. Language theory is the key to computing.

The software architecture can now be defined as all the components and languages that form the software system, and how they relate to each other. In practice, large parts of the entire structure is omitted when discussing the architecture of a software system. At the bottom is some well known language or runtime environment which is not further explored. It is also common to collect natural components in new abstract components called modules, libraries or packages. This will reduce the software architecture to something that is quite manageable, but still gives us a good overview of the software system.

A software product is then defined as an abstract component, which contain one or more components from the architecture. The reasons to define products are many, but the ultimate purpose is to specify what is delivered to the customer or user. The product can be split into subproducts for reuse or to break dependencies, but this must also be reflected in the architecture, which dictates where product boundaries can be drawn.

Software products are individually tracked with configuration management. They have a version and can be branched. Their quality is tracked with test reports and issues.

The product structure is very similar to the software architecture, but there will be more components in the architecture than products in the product structure. It can be trivial with only one product, or very complicated with hundreds of products and configurations which fulfill every imaginable need. It is up to you to decide where to draw the line.

Mission Impossible: A Wifi Photo Frame that doesn't Suck

In my ongoing project to build a wifi photo frame that doesn't suck I got a new idea. Why not combine an ordinary memory card photo frame and a memory card with built in wifi? Then I could automatically upload photos to the card which would be displayed in the frame. I started to seach the web, but it was not easy to get relevant hits for all the wifi adapters with Compact Flash formfactor. Finally I found Eye-Fi.

But it turns out this product sucks too. Why does everyone keep bundling nice hardware with proprietary services? Just give me the hardware! This is what's wrong with all the wifi photo frames on the market too, not to mention the crap that is Windows Media Connect. We are living on the Internet now and don't want to be locked into a last century desktop system.

Why doesn't anyone understand that an open wifi photo frame would sell in bundles?

What can I contribute myself you ask? My current plan is to connect an eBox-2300 equipped with a CF card to a LCD monitor, install Linux and write a couple of scripts that display a slideshow in the framebuffer. A web frontend could be used to specify RSS feeds or just plain web folders to fetch images from. Why complicate things more?


DVD Backup

This is the script I use to backup my DVDs.
mkdir dvd
dvdbackup -M -i/dev/dvd -odvd
genisoimage -dvd-video -o $1.iso dvd/*
rm -r dvd
The result is an ISO file which is named after the first argument to the script.

Install the required programs with the following command.
apt-get install dvdbackup genisoimage


SPARQL Literal Matching

I use the Jena implementation of SPARQL for a personal photoalbum. I have encountered a use case where SPARQL just can't help me. It is impossible to split a literal into parts. Take this RDF example.
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Johnny Lee Outlaw" .
If I want to use SPARQL to convert this information into a different schema where first, middle and last name are separate properties, it can't be done.
@prefix ns2: <http://some.other/namespace/> .
_:a ns2:firstname "Johnny" .
_:a ns2:middlename "Lee" .
_:a ns2:lastname "Outlaw" .
This could be solved by allowing variables to bind to regexp groups. Something like this.
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ns2: <http://some.other/namespace/>
?s ns2:firstname ?first .
?s ns2:middlename ?middle .
?s ns2:lastname ?last .
?s foaf:name ?fullname .
FILTER match(?fullname, "([^ ]*) ([^ ]*) ([^ ]*)", "?first ?middle ?last") .
I could of course have missed something that allows me to do what I want. You are welcome to correct me in the comments.

In this case, not being Turing-complete is a major drawback for SPARQL. If it was Turing-complete, the problem would be solvable in some way or another. The Principle of Least Power is very useful for data definition languages, but I doubt a SPARQL query is useful for an interpreter not being a query engine.

The easiest way to create a Turing-complete language is to embed it in a Turing-complete host language. Then it is always possible to go beyond the embedded language and use features from the host language when necessary.

STM32F4 DISCOVERY board and MEMS microphone MP45DT02

This is a repost of a couple of submissions I made on the ST Community site. It seems they are not searchable on the site, nor on Google, so...