Skip to content

No more noisy channels

A couple years ago I got it into my head that Information Theory held all the answers to the world’s computing problems. So, I got this book called The Mathematical Theory of Communication written by Claude Shannon and Warren Weaver. I was and still am too lazy to go through the math inside and really didn’t and don’t care much about it, but it’s old books like these (Shannon’s original article was published in 1948) that I think should have more impact on new “technological developments” or whatever you want to call them.

Let’s reduce the task of writing software to a problem of communication: transferring a message from point A (you) to point B (cpu). The message is the software’s high-level specification (source code). The message is conveyed by the information transmitted from A to B (machine code).

Problems arise when B doesn’t do what A wants because the source code has bugs. We’re all used to this and know how to fix it. After it’s fixed the machine code instructs B to do what we want. But, what else does it do? Is every instruction necessary? I’m not thinking about optimizing instructions for performance, but more about flow control and the logical implications of minimal message passing. For example, consider this function:

int
ComputeAdditiveOperResult(string oper, int a, int b)
{
    if ("add" == oper) {
        return a + b;
    } else if ("subtract" == oper) {
        return a - b;
    } else {
        throw InvalidAdditiveOper();
    }
}

The variable oper is used to select one of two useful branches. The “third” branch is essentially an invalid branch.

It only takes 1 bit to communicate which branch should be taken, but many more bits are present in oper because of its type, string. The oper parameter could have type enum {ADD, SUBTRACT } instead. Again, this isn’t about the tiny performance gain you’d get by comparing one bit instead of many; it’s about avoiding doing things that aren’t necessary.

We can all try to practice this, but I think it would be great if it were enforceable. Consider a programming language that warns you if you don’t use every bit of information you request. The function above could produce something like:

Warning: parameter 'oper' contains many bits of information, but only 1 bit is necessary

Doing it right would be tricky, because if instead of

throw InvalidAdditiveOper();

it was

throw InvalidAdditiveOper(oper);

then every bit of oper would be completely used by ComputeAdditiveOperResult, because using a variable as an argument uses every bit of the variable in the current scope.

Character data and such would be fine as long as it were printed or stored, but variables used for flow control could be given strict requirements. You could probably do this with enums, but it wouldn’t be the same. Realistically, this level of strictness would probably be more annoying than it would be useful, but I think it’s a good example of a new idea that was inspired by an old, abstract idea.

Read old books or don’t read any.

Post a Comment

Your email is never published nor shared.