Cheap Surface Clone

I’ve bought another computer. I’ve rationalised this because even after all this time I don’t have a machine running Windows 11. And today someone asked me if some of my code would run that platform. And I rather wanted to give them an answer.

I don’t want to upgrade my present machine from Windows 10 for several reasons. The primary one is that I have no need to. The second is that it would cost a lot of money. The third is that I’d have to replace pretty much everything which would mean a complete reinstall of all the software, some of which I don’t think I have licence keys for any more.

I’d much rather spend my cash on something with just enough power and disk space to do what I want with Windows 11. Which is where I introduce the Geotab 110. For less than the price of a Surface Go type cover I can get a complete tablet with keyboard and pen. I’m not expecting the earth when it arrives, but I am looking forward to discovering what kind of tablet PC you can get for 120 quids.

Heading to Driffield

David asked me if I fancied giving a talk to some sixth formers at Driffield. A chance to perform in front of an interested audience? Count me in. I took along a few toys, the trombone controller and my cut-price laptop. Much fun was had. The students were great. Lots of lovely questions (although one person did ask how tall I am - and after I had specifically told them not to do that). Kids eh?

I love telling the tale of embedded development. This is the best time ever to be doing it. Making stuff has never been so easy, so cheap, and so useful for building up your personal brand. I’m looking forward to going back some time in the future to see what they have been making.

David had brought in some trombones for me to look at, including the super shiny one above. It was nice to be able to compare the action of my sensor with something real.

The affair of the C# bang bang - !! - operator

A programming language is like any other language. It must evolve over time to reflect the ways that it is used. One of the things I love about C# is how it has grown over the years. One of the latest changes is the addition of a !! operator (otherwise known as the “bang bang” operator). This is causing a bit of debate, which is great because changes to a programming language should always be made on the basis of a proper discussion. But you might be wondering what all the debate is about. So here’s a quick explanation of what is going on.

C# has always had methods. A method is a thing you can ask an object to do. For example, you might have an object which you can ask to serve a drink:

barkeeper.serveBeer();
barkeeper.serveCoffee();

Then you might decide that rather than have a lot of different methods for different kinds of drink it would be easier to make a method that accepts an argument that tells it the kind of drink that is required:

barkeeper.serveDrink("Beer");
barkeeper.serveDrink("Coffee");

The serveDrink method can look at the value of the argument and decide what to do:

void serveDrink(string drinkName)
{
    // test the name and make an appropriate drink
}

So far so sensible, although we have made things slightly easier in one respect (we can use serveDrink method to serve any drink rather than having to make lots of methods) by making things slightly more difficult in another (the serveDrink method has to decide what drink is to be made and what to do if a matching name is not found). For example, what should happen when the following code runs?:

barkeeper.serveDrink("BEER");

The above code is asking for a beer, but the name is all capital letters. Does the method deliver a "Beer", or does it fail with an error. If it fails with an error, how does the user of the program know that an error has occurred? At this point we have to invent a convention for our application. We might say that the serveDrink method will throw an exception if it is given a drink type it doesn't recognise. That's fine as long as the behaviour is documented so that users of the method now how to use it.

But what about bang bang? I hear you ask. The operator is intended to make life easier for programmers by automating the handing of null references. Consider what would happen if someone did this:

barkeeper.serveDrink(null);

This code will ask for a drink but provide a null reference as the drink description. A null reference is not the same as an empty string, it is a reference that points to nothing. This is like asking the barkeeper for a drink and then falling over on the floor before you tell them what you want. An attempt by the serveDrink method to use this null reference will result in the method failing in some way.

Naughty hackers love this kind of situation. They might discover that asking for a null drink causes the serveDrink function to crash just after it has opened a bar tab, so that they can then continue to order drinks for free. They might find it serves out the most expensive drink in the bar.

As the person who is writing the serveDrink method you don't want anything like this to happen. So in the method you add a test to make sure that the argument is not a null value:

void serveDrink(string drinkName)
{
    if (drinkName is null) {
        throw new ArgumentNullException(nameof(drinkName));
    }
    // test the name and make an appropriate drink
}

The first thing this serveDrink method does is check to see if the drinkName is null. If it is null an exception is thrown which exits the method instantly. This exception may or may not be handled by the caller, that is up to them. However, we have made sure that the serveDrink method won't do anything stupid if given a null reference. (of course we now have to worry about the issues that might be caused by this method throwing an exception thougth - welcome to the world of error handling).

What the bang bang operator does is make the above test for us automatically.

void serveDrink(string drinkName!!)
{
    // test the name and make an appropriate drink
}

In this verson of the code an exception is thrown if drinkName is null. I don't have to remember to add the call. This might make my programs slightly safer. But it also means that readers of the code need to understand what !! means in this context. They might look at it and think that the drink is very important, or hot, or something else. They might not know what it does and add their own tests for null which don't do what they expect. Hence the debate.

My opinion? I split language features into two categories. Cake and icing. This is definitely icing. I'd never use it personally, as I like my error handling code to be very visible to someone reading my programs. Plus I don't like situations where readers need to know "special stuff" to make sense of what they see. However, it's not a thing I'd stress about too much either way. I just love the way that C# is still striving to move forwards.

You can find out more about this proposal and the debate here.

Day of disassembly

I spent a happy couple of hours today disassembling program code as part of an article I’m writing for Hackspace magazine. I love seeing the individual instructions that are actually going to be obeyed by the hardware. As an example, consider this statement:

  i = i + 1;

This adds 1 to the contents of a variable called i. This is the assembler that is produced for an ESP32 device.

assembler.png

The statements fetch the value, perform the addition and then put the value back in memory. Folks, this is what computers do. There is another layer underneath this called “microcode” which takes the value “881b” and works out that this means “add 1 to the value in A8”. The best description that I’ve ever found of how this works can be found in the book “Soul of a New Machine”, which is a fantastic read whether you are computer person or not.

Visiting the Jim Austin Computer Museum

If you know what this is, you'll want to go and see it. If you don't know what this is, you really should go and find out. Click through the image to more pictures. 

Jim Austin is a Computer Science Professor at the University of York. He has a lot of computers. A lot. I've got one or two. He's got all the other ones. Today he was kind enough to give us a guided tour of the barns where he keeps them all. We were there for several hours, but it felt like several minutes. And I'm sure that all we did was scratch the surface of what is there.

Jim has computers going right back to the start of computing. Persistence and being in the right place at the right time with a lorry has meant that he has mainframes, mini-computers, micro-processors and everything in between spanning the entire computer age. 

He takes the view that this is heritage stuff and I think he is so right. These machines have totally changed the way that we live our lives and the way that they have evolved is quite breathtaking. It is very strange to see so many things that were state of the art in their heyday, and I remember watching them on TV science programs in the past being celebrated as the future.

In a perfect world we'd have all this set out for mass public access. York has a fantastic railway museum that tells the story of how the railways revolutionised the world. We need something similar for computers. Last year I was lucky enough to get to visit the Living Computer Museum in Seattle. The stuff that Jim has deserves to have a setup just the same. Only bigger. 

You can find out more about the museum here. If you live in the Hull, York area you should see if you can get a chance to see what is there. If you live anywhere else in the world you should also try to get to see the stuff. And I don't think you'd regret the trip.