Learning through games


I’ve got my two button game working now. It’s fun watching people play a game that you’ve made. They start doing things that you weren’t expecting. But sometimes you find out other things too.

The gameplay (press the red button if there are more red lights lit, blue if more blue) is simple, but I make the task more interesting by adding more colours and making the colours move around the lights. Then I thought I’d make the lights flash on for half a second and then off, so that the player has very little time to count them.

This actually makes the gameplay seem easier (at least for me). The brain seems to retain the information for a while so that you can work out the answer, even with a very brief look at them.

I think this is the basis of “flash cards” although I may be wrong. But it is a useful reminder of the way that you can start going down really interesting tracks when you start fiddling with games.

Collapsing Regions in Visual Studio


I like using regions in Visual Studio. They make it much easier to move around code. I’m writing C++ at the moment and functions and code blocks are automatically tuned into regions, which is nice.

If you want to collapse and open them quickly there are a couple of control sequences that you might find useful.


This collapses all the regions. You can hold down the control key and press M followed by O.


This collapses all the regions recursively. So if you have regions inside regions you might end up with just one line in the editor if you use this..

These sequences are toggles, so pressing them again will open all the regions. I find them especially useful when copying or moving code, in that you can select the collapsed region and it will select all the code in the region.

GitHub Two Factor Authentication with Microsoft Authenticator

Microsoft Authenticator.PNG

I’ve just turned on Two Factor Authentication for GitHub. It occurred to me that seeing as how GitHub is now my “weapon of choice” for organising anything, and I can make my own private repositories, I should take some steps to keep them private.

It’s actually very easy to do, once you have an app that can produce “Time Based On Time passwords” or TOTPS. I’m using Microsoft Authenticator. I figure that since Microsoft now own GitHub, it’s likely that Authenticator will work well with it.

Software Engineering Philosopy

This picture is one of mine. You can find it on  Flickr

This picture is one of mine. You can find it on Flickr

Had an email from a Peter who’s reading the C# Yellow Book at the moment. He asked about how to learn more about software engineering. I quite like my reply, so I’m putting it in my blog….

I worry a bit about too much emphasis on "software patterns". I just tend to write code that solves the problem, and then discover afterwards that I've used a particular pattern. Things like "dependency injection" just seem like programming common sense to me, but then again I have been programming for a very long time.

By all means read up on the different patterns, but do it from a perspective of refining your technique, not finding a quick solution to a problem. If you use a pattern without understanding how it really works that can end badly.

My strong advice is just to keep writing code. Build your knowledge and develop a habit of looking at existing systems and trying to figure out how you would make them work and what design decisions were made when they were created. If you do it right you’ll be learning new stuff and having new ideas all the time. I still am.

A lot of programming and software design is down to practice and experience, just like any other field. And you also need to remember that any working system is built up of compromises and that it is very rarely that you will find the best solution. You might find the fastest, or the smallest, or the quickest to build, but not the best.  So decide what kind of “best” that you want, and go for that.

Show your work to people


I've spent a chunk of today improving the Hull Pixelbot software. The improvements were identified when I was showing off the software at the hardware group last week. There's nothing like showing off your stuff to flag up faults and issues in it. Things that seemed like carefully thought out design decisions turn out the be horrible ways of doing things. And if you're lucky the person you're trying to impress will come up with ideas and suggestions that will make what you've building even better.

Perhaps you might be a bit afraid of doing this, but in my experience it makes a huge difference to the quality of a product to have someone take a look who hasn't spent ages living with it. 

File Comparison in Visual Studio

file compare.PNG

Today I found out something that I didn't know that Visual Studio could do. It can perform file comparison. This is really useful if you've made a tiny change to a file for a very good reason at the time, but have completely forgotten where the change is, or why you made it. I never do this kind of thing myself you understand, but I've heard that some programmers make this mistake from time to time. 

There are lots of file comparison tools out there of course, along with quite a few plugins, but it's nice to see that Visual Studio can do it right out of the box. 

The only problem is that that finding the function is a bit tricky. You have to use the Command Window (which you open using CTRL+W, followed by A) or by selecting it from the View menu (take a look in the "Other Windows area if you can't find it). 

Once you've got the command window you can type in the command Tools.Difffiles followed by the names of the two files you want to compare. There is some rather neat auto-completion of filenames which makes it a bit easier to navigate to the files that you want, and I love the idea of being able to type three f's in a row in a meaningful context. 

Anyhoo, the comparison window that you get is rather nice, and it works well. 

Making a Windows Home from home

I've used Virtual PCs for quite a while. My first proper brush with the technology was when I was building and configuring Class Server systems. I found it kind of magical that I could have several "fake" PCs running inside my one real one. And I loved the way that if anything bad happened to the hardware I just had to spin up another PC on a replacement device.

I've started using them again. I'm writing a "Begin to code Python" book and I'm worrying about the installation documentation. It's important to be able to show the installation just as it would be for someone running Windows 10 Home Edition on their brand new laptop.

So I've built a brand new Windows 10 Home Edition installation on a virtual machine. Took around twenty minutes or so. And the beauty is that I've taken a snapshot of the empty machine, so I can easily "wind back time" to before the installation and practice it again.

I used a really nice guide which you can find here

Joe Stead talks .NET Blub

c4di is having some great evening events at the moment. On Monday we had CodePen, and today we had Joe Stead talking about future platforms for .NET development. Well presented and thought provoking.

Some interesting musings on how programmers are defined by the languages and tools that they use and how important it is to be looking at what's out there and developing professionally. Plus a look at some shiny new stuff.

I've come away with a list of things to investigate, and I'm pretty sure that most of the people there (and it was a good sized audience) were the same. 

The Mysterious M3U File Format

The music player in my car is quite good. I can plug in a memory card and load up a whole bunch of music. The player interface also talks enticingly about "playlists", but I don't seem to have any and there seems no way in the car to create them.

So I do some digging. After a bit of searching I discover that the car will accept playlists in the "M3U" format. This format can be exported from some music players and you can also find programs that will create M3U files. Which is useful.

But, me being me, I fancy writing my own M3U file generation program. So I do some more digging. It turns out that the format of an M3U file is a list of tracks in a text file.

That's it. No cunning schemas or encoding techniques. Just a list of names. The only fiddly bit is in the file extension which I think needs to be m3u for non-Unicode and m3u8 if the text is UTF-8 encoded. You can make it more complicated by adding directives (there's a good description here) but it turns out that I can start making these exotic sounding files with just notepad. I'm going to have a go tomorrow.

There's a lesson here folks, which is that in the Wonderful World of Computers(tm) it is quite frequently the case that something horribly complex sounding will actually turn out to be quite simple. Don't work on the basis that "it will always be too hard for me to understand". Every now and then something is as simple as the simplest thing it could be.

Appalling User Interfaces - App Suggestions by Siri

I seem to need to have an Apple phone. My favourite, Windows Phone, doesn't do all the things I want, and I've tried Android and that was fairly appalling too. What can I say? I'm picky.

One trick that the iPhone plays drives me completely nuts. The phone provides "Siri App Suggestions" based on the things that you do most. You can use these favourites to slightly compensate for the horrible way that the iPhone manages large numbers of apps on the device.

The suggestions are based on your use of the phone and are updated each time you visit the screen. But here's the appalling bit. They update and redraw themselves in the fraction of a second between the page appearing and you actually selecting something.

So your finger can head for the Nest icon, but by the time your digit touches the screen the icon underneath can be replaced by a different application. So the wrong thing is selected. Most annoying.

This single piece of stupidity makes the feature completely useless to me. Here's a tip Apple, why not update the sorted list before you display it on the screen?

Buy more than you need

I'm kind of cross with myself. I've broken one of my own rules. I needed bits for 8 robots. So I bought 8 sets of bits. Stupid stupid stupid. You should always buy a few spares in case of failures. It's not that they are expensive. And you can always use the spares on other projects.

Of course a few were duff, which meant that I couldn't make all my robots. Of course (cunning bear move) the faulty parts were the ones I used last. Fortunately have have friends with similar interests (thanks Ian and Robin) so I was able to grab some spares, which is how come I'm sitting on the train with 7 working robots (I couldn't fit 8 in the case...)

Bear Wrestling and Hardware Development

I think that building devices is a bit like wrestling a bear (not that I've ever actually done any bear wresting). It's an ongoing struggle and then, just when you think you might be winning (always a dangerous thing to do) the bear pulls out a killer move and knocks you flat on the floor. 

I've just suffered from this. Nasty bear.

I've been building HullPixelbot devices for c4di and AzureCraft and connecting them to my home wifi for testing. It's been going well (a dangerous sign). I'm controlling them quite successfully and thinking that I might actually end up with a working system. And then today everything slowed right down. Commands that previously took no time at all to deploy suddenly took ages, which is a problem because all the robots need to move at the same time. 

Of course I thought my software was broken and spent a couple of frantic hours trying to speed it up. But the performance was still rubbish. 

Then, at 3:00 am this morning the answer came to me. At the same time as deploying the final version of the code I'd switched to my portable WiFi router, rather than the home network. All the problems started then. Turns out that not all WiFi was created equal. Some is much slower than others.

At 3:30 am I was resigned to going off and buying a new router in the hope it might be faster. At 4:00 am I realised that I actually had a router I'd bought a while back for another project. Only problem is that it was running the Chinese version of the router firmware. 

So at 8:00 am this morning I was trying decipher Chinese menu screens and load a new version of the firmware into the router. I've finally managed to get it working and performance is back to reasonable again. One up on the bear. 

However, the most important thing about the "bear wrestling model of hardware development" is that you mustn't start to think that the bear hates you. He doesn't. He's just there to wrestle, because that is what bears like to do. You need to work on the basis that at some point the bear will step back, bow gracefully and say "I'm going to let you win this one". 

Appalling UI Design



I still like my Apple Watch. I still like my Apple phone. But mainly for what they can do, not the way that they do it. Going back to my Windows Phone always puts a smile on my face, as I get to use a user interface that is properly usable and scaleable. Then the smile disappears when I find I can't read books or do anything much with it. 

For a company that prides itself on design Apple should be ashamed of the above screen. Take a look at it and decide whether or not the watch will make sounds. After a while you might deduce that if silent mode is off, the watch might make sounds. Although you might also be confused because the icon shows a bell with a line through it which might imply silence. The icon is not lit up - although it can be - something that you need to know to make sense of what is happening here. 

Ugh, ugh, and ugh. Anyone who thinks that user interface design is easy should take a long hard look at this and consider how they would do it. They are almost certain to come up with something better than this mess. Me, I'd take away the icon and use the words "Noisy" and "Silent", it would be a lot clearer for your's truly. 

Update: Turns out I can't spell appalling. That's ..... not good. 

mDNS Manager for Windows 10 IoT Universal Apps

You know how it is. You have built a robot army that you're going to use to take over the world, but first you have to get them all under your control. And if you are using tcp/ip (the world domination network of choice) then you have to give them all an ip address and then put those addresses into your world domination program.

mDNS makes this much easier. It's how Apple's Bonjour network discovery works. A device running mDNS is discoverable on a local network. You can find all the hosts and their ip addresses, along with the services they are providing and the ports. Windows 10 provides a Watcher service that you can use to discover all the machines on a local network, but it is a bit of a pain to use.

So I've written a tiny mDNSManager class that you can use to create and manage a watcher object which will start a search for devices, tell you when it finds one and also present a list of all the devices it has found so far. It's very easy to use. 

You can find the source code for both the manager and a simple demonstration application on GitHub here

If you want to just use the manager in your programs you can install it from NuGet:

Install-Package RobMiles.mDNSManager 

It works on any Windows 10 device, including the Raspberry Pi, and it makes it much easier to connect to a large number of devices. There are mDNS samples available in the example applications for the ESP8266 devices in the Arduino IDE.

I'm using this to allow me to create a Universal Application that will control a bunch of HullPixelbot devices without needing to know their ip addresses in advance. 

Visual Micro Still Rocks

I bought Visual Micro a while back. Not that I really needed to. The free version is actually plenty powerful enough for day-to-day use. It was just that I thought the product was so good that I really should support it.

For a registration you get a key that works on three machines. I've been through a few machines over the years (as you do) and last week I found that my key didn't work for my desktop. I emailed them, they cleared the key and I'm back in business again. Thanks folks. 

If you are in any way serious about embedded development you should get this tool. The free Arduino SDK is OK for a while, but you'll fairly quickly hit limitations that will grate, and with Visual Micro you get all the lovely intellisense support and general niceness that comes with developing code in Visual Studio.

Visual Micro now works with all the esp devices and pretty much anything Arduino shaped as well. It's got some very interesting debugging support too, but I tend to rely on code instrumentation (print statements) when I'm writing embedded code, so I don't use it very much. Go get it. 

Cheese Yellow Book back from the printers

We got the latest copy of the C# Yellow Book back from the printers today. We had a whole bunch of copies printed for the new first year course, and to give away on Open Days. 

This is the "Cheese" edition. The changes are mainly evolutionary. Thanks to everyone who contributed comment and pointed out mistakes. The pdf version will be going live later in this week. Then I'll update the Kindle version. 

Nuget source settings cleared after Visual Studio upgrade

The title says it all really. I got all excited about the new release of Visual Studio and so I upgraded my copy of Visual Studio 2015 Community Edition immediately. The upgrade has some nice new features (and I want to use it to write Xbox One programs) but it did do one thing that confused me for a little while. It clears the source setting for Nuget.

The result is that all your Nuget fetches fail. However, it is easy to put back again by going to Tools>Nuget Package Manager>Package Manager Settings and setting the checkbox as shown above. 

Snaps now has a 2D Game Engine

If  you've not heard much about Snaps (my library that's designed to make it easy to learn to program C# which I'm using in a forthcoming book) then that's because I've been too busy writing the book (and the Snaps) to tell anyone about it. But today I built some Snaps that I'm really quite proud of. I've now got a tiny sprite library and a gamepad which you can use to make 2D games.  I'm going to use it in the chapter where we talk about class hierarchies. 

It's not a particularly fancy engine really. It runs inside a Windows 10 Universal application and uses all the XAML display elements. Having said that, I can get reasonable performance on my machine which has no graphics acceleration and it even runs on a Raspberry Pi. 

For learning to program (and of course for Cheese Lander) it's absolutely perfect.