Fun with MineSweeper

I spent some of today working on the coursework for our First Year programming course. Every year we get our students to create a simple game. Last year it was Battleships. This year it is MineSweeper, a game with a long and honourable history, having been shipped with every version of Windows right up to Windows 7.

One of my rules is that I don’t ask the students to do something that I can’t. At least not in the First Year…

So I spent a happy afternoon putting together a simple version of the game and writing the notes to go with it. I’m so pleased with what I ended up with that I might make a version for the Zune. It is a really nice platform for that kind of thing.

The first part of the lab goes live next week and should be great fun.

Free XNA Curriculum Materials Now Live

If you have been wondering about what all the “Today I have Been Mostly Writing” posts last month were all about you can find out as the courseware is now available on Microsoft Faculty Connection:

This is a complete programming course which is designed to be taught over 10 weeks at a rate of 6 sessions a week (although you can pull individual sections out and use them if you wish).  There is a course matrix that sets out how to sequence this.

The course teaches programming from first principles, using XNA games as the basis of all the sample code.  There are extensive tutor notes on the slide decks and a sequence of step-through labs for students to follow. There are even revision tests for each section.  It is based on the chapters in my textbook, which is the first link in the above list.

You can download the material without signing in, by selecting the “Skip this Step” option on the download page.

If you are going to use the material in any way I’d love to hear how you got on.

Breaking in With Thirteen One Magazine

I met up today with Craig from Thirteen 1 magazine. They are doing a set of articles on breaking into the games industry, and I’m going to be recording some video podcasts for them about learning XNA.

Don’t worry, the camera won’t be pointed at me. Instead I’m going to capture the steps you need to follow to set up your computer and then write some XNA games. Should be fun.

Meeting the Mobile Team

Today we got all got on busses bright and early and headed off to the Microsoft campus at Redmond. It was quite a nice morning, and on the way we saw a rainbow which seemed to have its roots in the middle of Microsoft, which I thought was interesting. Unfortunately by the time I got my camera out we had driven past it.

campus

The rainbow is about 20 feet to the right of this picture.

We had a bunch of presentations from product team members. I hope they found our comments useful. After that it was time for more mingling, and then a bus back to the hotel.

nightshot02

I remembered my camera this time.

Doncaster Meeting and Programming Puzzle

Went to Doncaster for an exam board today.

3314441850

The meeting room had this very impressive chandelier, which lent a lot to the proceedings.

Spent some time chatting with Colin, the external examiner, about programming matters. We were talking about good practices, properties and get/set methods and the like, and a question occurred.

“Why do some types in C# have a Length property (for example String and Array) whereas others have a Count method (for example List)? Both of them do the same thing, so it seems to be silly to have different names for them.”

Colin and I think we know the answer. But do you?

Portugal DevDays 09 Demo Code and Presentation on SkyDrive

I’m using the fancy new Windows Live SkyDrive to share out my presentation and the demo programs from yesterday:

  • You can find the presentation here.
  • You can find the demo programs here.

SkyDrive is actually rather neat. You can attach it to your Windows Live account and it gives you 5GBytes of storage which you can use for public or private data storage.

SmallBasic

If you want to rediscover the joys of writing little programs and doing fun things with computers you could take a look at SmallBasic. It is inspired by the tiny Basic interpreters that you used to get with your Commodore 64 or BBC micro and lets you write programs using a very simple language in a friendly IDE.

I’m a great believer in starting to program by keeping your focus on the algorithms and things like this can only be good. Although I’m not sure about the Goto statement figuring quite so large....

http://msdn.microsoft.com/en-gb/devlabs/cc950524.aspx

Moderation in All Things

I've been marking first year programs for the last couple of days. We had the code demonstrated at the end of last year, and I'm going through all the submissions moderating marks from the various assessors and marking any that we didn't get a chance to see. Some of these folks have only been learning programming for a few weeks and yet they are producing results that hit the spec., which is great.

It is funny how I can see all the mistakes that I made when I was learning to program coming round again. Things like using block copy to repeat code rather than loops or methods. Adding complication when you should really be simplifying the code and fixating on things that aren't actually important but seem to be at the time.

I was going to spend a couple of lectures going through my "perfect solution" to the problem, but then having seen the submissions I've realised that there is no perfect solution (just like real programming) and so I think I'll spend the time putting sensible behaviours into the context of the program they were building.

I'm really looking forward to next semester.

PDC Wrap Up

This is my last night in LA. The PDC has finished and I'm squeezing things into the suitcase. But I thought I'd put down a few things which I've seen over the week, which has been as excellent and inspiring as usual.

Microsoft Surface

I want a Surface device. Want, want want. I've had a chance to play with one, I'm even in the Surface community, which means that I can download and play with the surface simulator, which lets me create applications and run them on my PC.

If you've not seen Surface you are in for a treat. Nobody would say it is portable, think coffee table with a 24" flat screen TV laid on top, but the things it can do are amazing. Thanks to a bunch of cameras beneath the display it can see and track multiple finger inputs along with objects tagged with a kind of dotty barcode. The  way that you can move and manipulate objects on the screen is truly wonderful, and a massive pointer to the fact that the days of the mouse as an input device are definitely numbered.

I went to a Surface presentation and also had a chance to play with the software and the device itself. You can't say that version 1 of the hardware is going to find its way into every home and office, but when the technology develops, and it will, you will find that all the software interfaces that you will need to make the best of this way of working will be tried, tested and in the operating system.  Find out more here.

Home Server

You might not have heard of Windows Home Server. It tends to only be available when you buy the server hardware that powers it. It provides resilient, scalable storage for all your data at home, and can also be used to tie all the machines in your house into a unified network.  What I hadn't realised is just how it makes itself available to systems outside your house. You can set up a proper, secure, remote access which you can use to access applications running in your own personal "cloud". I'm not sure if anyone will want to go quite that far, but they might like to get access to all their home media when away from home. Find out more here.

Oslo

Don't know what Oslo is? Neither did I until yesterday when I went to a session because Boss seems to be interested in this stuff, and he knows a good thing when he sees it. Oslo is a great way to build line of business applications. It is a modelling language (also confusingly called M) which lets you express the design of your application in a way that lets the data do the talking. Because the starting point of your new application must be a good understanding of the information that underpins it you end up writing much less program code. And that has to be a good thing.

For me the great thing was that all the stuff I'm presently hammering into my second year students (yes, that's all you fighting with the "Make It Yours" specification) about establishing the scope and then moving onto the design of the underpinning data fits very nicely with Oslo. Find out more here.

C# Futures

C# is my favourite programming language in all the world. For now. The new version promises to be even favouriter. It promises something that is really interesting, dynamic types.

Up until now C# has been very strict about what you can do with what. This is all to the good, in that it stops your program asking an object to do something that it doesn't have a behaviour for. The C# compiler will refuse to run a program until it can determine in advance that everything the program tries to do will end up being possible.

Unfortunately this gets in the way when you are trying to combine objects in a looser way. More modern languages have a much more relaxed approach to this kind of thing, finding behaviours dynamically as the program runs. In the dynamic programming world you don't actually have to be a duck to fit in. As long as you have a quack method you can be treated like one.

In a really superb talk Anders Hejlsberg showed how programmers will be able to mark objects as having a dynamic type which is resolved at run time. This all happens in a way that preserves type safety, meaning that C# can mix it with languages like Javascript without making the code more dangerous.

This is all being built on a new version of the runtime for .NET which will also underpin other dynamic languages like Iron Python and Ruby.

But the best bit, the very best bit, is the way that soon the C# compiler will be componentised so that it can be driven from within your program. This brings an old school Basic flavour to the language, where you can type in lines of C# and have them compiled and run before your eyes. This was amazing. A fifty line program produced what looks suspiciously like a C# interpreter. Watch this for more.

Coding 4 Fun

I also met up with Andy Sterland and James Lissiak from Hull (now with Microsoft) who were manning the Coding4Fun stand and telling everyone about their Unreal Tournament fun and games. They had been given white coats to wear.

2980382465

There is no truth to the rumour that they arrived in a green van.

Dan Fernandez was kind enough to give me a white coat as well, on condition that I write something for Coding4Fun in the future. I'm very pleased with it, and plan to wear it for special lectures at Hull.

Don Box, Chris Sells and Azure

Azure is the new Windows Framework for Cloud Computing. Don Box and Chris Sells are two of the best programming presenters I have ever seen. They put together a session that set out neatly how much fun you can have writing code and running it in the cloud. if you get the chance to see the vide of this session you should.

2984240564

Chris and John getting started

Multi-Touch Input

Multi-Touch input in Windows 7.0 and Surface are heading in similar directions and will eventually meet up in a later version of Windows Presentation Foundation. If you really want to work with multi-touch perhaps the best way to would be to get hold of a rather spiffy Touch Smart from HP. I had a go at the lab which shows how Windows messages are managed with multiple touches. Me being me, I had to fiddle with the code a bit.

2983384977

Drawing with added jaggies.

The MicroFramework

It was great to see the Micro Framework on the exhibition floor, with even more hardware and the new Dare To Dream Different challenge. Which you really must enter.

11MicroFramework

Down on the Micro Framework stand.

They were showing off the new board that the 100 top entries for the contest will get to play with. This is an absolutely superb piece of hardware with lovely colour touch screen, network connection and all sorts. Lucky finalists will also get inertial sensors and wireless communications with which to realise their idea. I'm going to get a bunch of entries from Hull, some silly and loads sensible.

Swag

2981240588

We say that these trips are all about finding out about new technology, meeting the best experts in the field and learning new things, but actually, they are all about swag. Above is a snapshot of the swag process. I seem to have ended with around 10 T-shirts, two books, a slinky spring, a solitaire game, a flashing bouncy ball, a dot matrix badge computer and a screaming flying monkey. Not bad.

PDC Research Keynote and Boku

Today was the third day of "keynote" presentations. These are big impressive events, but I must admit that a lot of today's left me a little deflated. The best bit was the description of the way that computer research is informing work on the behaviour of diseases such as Aids. Apparently it is not just a question of computers providing data processing power to crunch data, it is the way that advancing knowledge in the behaviour of software systems is informing the work on the virus. That was fascinating.

Less compelling was the presentation of Boku, a new development that purports to teach programming to kids. (Rant warning: I feel strongly about this one)

Before he introduced the item, Rick Rashid told the audience how his kids are finding out how to use Visual Studio to create software. This is a good plan. They are learning something which will be genuinely useful in their future.

Boku doesn't use conventional tools or notations. You get to control funky shaped creatures in brightly coloured landscapes and make them zoom around and shoot at each other. The language is what I call "sort of" programming in that you do learn that you can put into place things that control what stuff in the game does, but I'm at a loss to understand how you could ever transfer any skills attained doing this into a real, problem solving, situation with a proper language in use today. I really can't see even Rick Rashid feeling that he would be doing his kids a favour by pointing them at things like this.

I'm probably missing the point here, but I don't see how this will engage future students with Computer Science.  It looks like it might be fun to play, and it sure looked great fun to create, but at the end of the day I feel strongly that Computer Science is about solving problems in the real world, and I don't think that Boku gives any kind of useful lead on that. Modern computer games have significant problem solving as part of the gameplay and I really don't think you have to make any half way house products like this I'm afraid.

The C# Yellow Book is now in PDF

Students lucky enough to come to Hull get a free copy of my C# programming book (this year in a snazzy yellow cover). If you come to see us on an Open Day we will also give you a printed copy. Until recently the only way to get sight of the book was to come to Hull and get one.

However, that has now changed, you can now download a PDF of the book from /c-yellow-book/.

Please let me know what you think.

Software Design

I'm still writing stuff that is intended to teach programming. Great fun,but very hard work (apparently). I'm up to the bit where I'm trying to make a game more interesting.

BlockBuster
..but how do you detect when all the red bricks have gone?

I am recreating a game I first made many years ago in Lucidata Pascal on a South West Technical Products 6809 based microcomputer.  It is a simple breakout clone with one or two interesting touches as you go through the game. Apparently it was responsible for a lot of lost time in the Psychology department at the time I wrote it, because they had the same computers and spent ages playing it. Chris used to spend entire lunch-hours on it, holding a ruler against the screen to line up really tricky shots....

Anyway, I digress. The place we've got to is where we have a row of blocks and a ball, and we can destroy the blocks with the ball. It gets a bit boring when all the blocks have gone, so our program must detect when the last block is removed. There are essentially two ways you can do this, you can keep a counter of blocks that are left and reduce it each time you remove a block, or you can look through the blocks and see if you can find any which are still visible. But which is better?

Keeping a counter has the virtue of simplicity and makes the smallest program. However it also adds a counter variable which is coupled with the array of blocks. If the counter and the array get out of step for any reason the program will misbehave. If the program checks the array each time there is no question of this happening. In other words one design leaves the system open to bugs that could not occur in the other. I'm trying to get people thinking about the craft of software development and into the habit of worrying about things like this when they write programs.

I often get asked "What is the best way to do this in software?" as if there is an solution which is perfect in every way. I tend to reply that there usually is no such thing a best solution, there will be a fast one, one which doesn't use much memory, one which has the shortest program code and so on. To that you can hopefully add "simplest" which is the one that I tend to go for, unless I'm really worried about performance.

Casting?

I'm writing some new teaching material at the moment. It is going roughly half as fast as I expected, which is about right in my experience.

Anyhoo, I'm doing casting, where you tell the compiler to convert from one type to another by putting the type in front:

int i, j;

float factor = (float) i / j;

I have to cast i to floating point in the sum, otherwise I get an integer division and no fractional part.

In other words, in the above code if the value of i is 1 and the value of j is 2 I want the value of factor (1/2) to be 0.5 (floating point division) rather than 0 (integer division). I get this result by casting i to float in the sum. C# uses floating point division with floating point operands, and everything comes out OK.

This is a standard computing thing, most languages provide support for casting. And I started to wonder why it is called casting? Popular wisdom seems to be that it is related to casting things in a foundry, where you pour liquid metal into a mould of a particular shape. The shape of the mould determines the result of the cast. So by casting you can change one thing into another.

However, I've thought of another way to look at it. You can think of casting as making a movie. You take an actor (Christian Bale) and cast him as a character (Batman). For the duration of the film the character will behave in terms of the role they have been cast into. This even works when we consider stupid casts. In C# you can't do things like cast a string into an integer. In films you can't do things like cast Christian Bale as City Hall. I quite like this way of looking things, but one thing does worry me. Maybe this is the original meaning, and it has taken me years to figure it out.....

St Anne's Masterclass

We had a bunch of students come to see us today from St. Anne's. They were great. As usual I took a picture of the audience at the start, while they were still smiling.......

2604578140

Audience View

At the end of the talk I did a kind of Aibo vs. Pleo thing, where I turned Digby and Trevor loose together to see what would happen.

2604580742

Will they fight?

They seemed to ignore each other most of the time, although Digby did keep trying to climb off the edge of the table.....

Mr Ten Percent

I've spent a lot of time over the last few weeks working with my final year project students and their reports.  They've been sending me drafts and I've been adding comments. This year has been great, because most of them have really engaged with the process, coming to regular meetings and responding very well to what I've said.  It has been nice to see the drafts improving in quality with each pass.

The actual hand in date is this Thursday, and I'm quite looking forward to seeing the finished results. If you are writing something it is very important that you go through this review phase, and you allow time to do it. I reckon that a properly written report can add ten percent to a project mark so it is worth the effort.