Skip to content

What Speed Costs You

Going down to the metal buys speed and sells comfort. This is what you hand over, with nothing left off the bill.

The last two units made translating once sound like the obvious choice. It is the right choice for a game. It is not free, and it is better to know the price before you arrive at a machine than to find out there.

Here is what you hand over. There are three things on the bill.

You lose the safety net

An interpreter reads your line at the moment it runs it. So when you write something that makes no sense, it can stop and say so, and point at the line.

An assembled program has no line to point at. The names are gone. What runs is 1 1 2 3, and if you meant 1 2 1 3, the machine runs what it was given. It does not know there was a mistake, because it never saw the version with the mistake in it. It saw numbers, and it ran them.

So on a real machine you will not debug by reading an error. There is no error. You will debug by watching: what did it do, what did you expect, and where do they part company? That is the method from Structure, and here it is the only method there is.

You say more

FOR i = 1 TO 1000 is one line. The machine has no instruction for a loop. It has instructions for adding one, for comparing, and for jumping back to an earlier place, and a loop is those three arranged carefully.

A compiler does that arranging for you. An assembler does not. Every step the machine takes is a line you wrote, so an assembled program is longer than the same program in any other form, and more of it is there to steer the machine than to say what you meant.

You choose one machine

Our tiny machine’s numbers meant nothing to any real processor. A real processor’s numbers mean nothing to any other. 1 1 2 3 runs on the machine whose table it came from, and nowhere else.

Write a game in an interpreted language and the interpreter carries it between machines. Write it in the machine’s own numbers and it belongs to that machine. Every game in this curriculum was written that way, and every one of them is a game for one computer.

When it’s wrong, see why

  • You cannot find the mistake because nothing told you. Nothing will. Watch what the program does, decide what it should have done, and find the line between.
  • The program is enormous for what it does. That is the cost of saying every step. It is normal, and it does not mean you did it wrong.
  • It does not run on the other machine. It was never going to. The numbers belong to the processor you wrote them for.

What you’ve learnt

  • Translating once sells the safety net: no line to point at, no error to read.
  • It costs more lines, because the machine has no instruction for an idea.
  • It binds you to one machine, because the numbers are that processor’s.
  • On the metal you debug by watching, and that is the only way there is.

What’s next

That is the whole bill, and it is a real one. In Unit 5 we look at what it buys, and then do the one thing this module has not been able to do: put it on a clock.