The Five Knows of Programming

I've been teaching programming for a very long time. I'm still waiting to get properly good at it. In the meantime I'm given to thinking about what it means to learn how to program. I've narrowed it down to five "knows".

  1. Know what the computer does.
  2. Know how to create a program.
  3. Know how to automate a task that you yourself can perform.
  4. Know how to think like a computer.
  5. Know how to structure and manage your solutions.

I've been teaching the First Year course for the last few weeks and I reckon that we are at level 3 at the moment, moving on to level 4. This is a crucial time.

At "Know level three" you can take something you would be able to do yourself and write a program do perform that action. One example we do is deciding whether or not you can see a particular film. If your age is lower than the rating for that film, you can't go in. When you write the program you can imagine yourself selling tickets and deciding whether or not people can come in.

Level 4 is quite different. You have to let go of how you would do a task and try to think how you could make a computer do it. Sorting is a classic example of this. If you gave me 20 numbers to put in descending order I'd be able to do it, but I'd not really be able to tell you how I did it. To write a program to sort 20 numbers you would make it do the task in a way that a human never would (for example bubble sort). This is the hardest part of programming. Up until you hit level 4 you can think you are doing very well. Ifs and loops make sense, as do variables. And you've even written the odd program. And then wham, you suddenly find that you can't do it. And I mean really can't do it. This can be very painful and demoralising.

Today I did a tutorial with the students where we explored the transition from level 3 to 4. The best advice I have on this matter is not to stress if the penny doesn't drop first, second or third time. Don't think of it as a technical problem (I must re-read my notes so that I understand arrays better) but think of it as a "way of thinking problem".

Work with what you know a program can do (stash things in arrays, get them back, work through elements, compare values and do things with them etc) and then try to figure out how these abilities can be used to solve the problem.

Consider lots of related problems: find the biggest item in an array, find the smallest in an array, count how many times the value three appears in an array etc etc and notice how fundamental behaviours (working through the elements of the array in sequence) can be used to solve a whole class of problems. Don't worry if your answers seem complicated to you. You get better with practice, and some things are just tricky to do.

I learned to program a long time ago, but I still remember the worry of "What if I don't get this bit" every now and then. Your best bet is to start early, find friends to discus it with and keep the focus on what you are trying to do. And you'll be fine.

Games and Learning

On the face of it the video games Animal Crossing Happy Home Designer and Sunset Overdrive don't appear to have a lot in common. But in one respect they are quite similar. Both make complex demands of their players. Games now have to deal with the fact that rich, complicated gameplay makes it necessary for the player to know stuff.

When I played Sunset Overdrive a while back I was impressed with the design of the tutorial levels and the lengths that the game went to as it made sure you new what all the weapons did and how and where to use them. There was also a well managed introduction to the overall plot and the characters. Playing Happy Home Designer (a fun little title as it turns out) I had a very similar experience. As a player you have to learn how to work in the various design scenarios and this is very well introduced into the narrative.The game even has a cash based system that you can use to learn more things in order to unlock new abilities.

People have been going on about game based learning for years. It's interesting to see that the game makers are getting good at putting the learning into their games too.

New Students Welcome Party

We had a pretty good turnout

We had a pretty good turnout

It was our First Year Welcome Party today. Video games, silly quizzes, free beer and food. What's not to like?

Using the "TagoMatic" to get your beer. Turns out that green is good.

Using the "TagoMatic" to get your beer. Turns out that green is good.

We all had RFID tags that we used to pay for drinks. Everyone got their drink and then I got the best round of applause of the night for using my "magic tag" to reset the tags and allow everyone another turn at the bar. If you got one of our "Tags of Fun", please hang on to it, I'll be using the tag reader in lectures to give out prizes....

This guy won the Super Smash Bros 8 player tournament

This guy won the Super Smash Bros 8 player tournament

I am so going to buy this Amibo now, what with me winning a round when I played as him.

I am so going to buy this Amibo now, what with me winning a round when I played as him.

These folks won the quiz.

These folks won the quiz.

Car Racing

Car Racing

Much fun was had playing Gang Beasts, a deeply silly multi-player game

Much fun was had playing Gang Beasts, a deeply silly multi-player game

We had a great time. I took a bunch of other pictures that you can find here.

Welcome to Hull Computer Science 2015

One of the people in this picture is not a student. Can you tell which?

One of the people in this picture is not a student. Can you tell which?

I'm all back from Japan now. With jetlag and everything. Lots of fun was had. Stuff that happened will probably end up being the subject of numerous blog posts over the next month or so.

Today we gave our first induction lecture to new students. Thanks for coming folks, I hope you enjoy your stay with us. If you want to view a larger version of the picture above you can click through the image to Flickr and download the large version. 

If you are a new student at Hull don't forget the party tomorrow night (free drinks and food) and the event on Saturday.

Hull Knowledge Factory Student Talk

At least now I know what happens if I try to use the Panorama feature of my camera to take a picture of the audience. Sorry if you were cut off.

At least now I know what happens if I try to use the Panorama feature of my camera to take a picture of the audience. Sorry if you were cut off.

I did a talk for a bunch of Knowledge Factory students today. These are folks who will be joining us at the end of the month as students, but have come along early to spend a few days getting a taste of university life.

The subject of the session was the joys of "Making Stuff" and it was great fun. Thanks for being a lovely audience folks. During the talk I mentioned some bits and bobs and I said I'd post references for anyone who fancies following up on the things I talked about.

Arduino

Arduino is the name of a family of embedded computers of different sizes. These are the kind of computers that you would put inside a device to control what it does. I use them in my wedding lights and other gadgets that I've made. You program them in C using a very easy to use framework that you can download for free from the Arduino web site.There are versions of the framework for Mac and PC. You put a program into the Arduino device and it runs that program each time the power is switched on.

You can buy Arduino branded devices but they are a bit pricey. It is much cheaper to go onto eBay and just search for Arduino. A company called Sintron makes some very nice kits of parts to play with, these start at around 30 pounds. Once you have the kit just search the web and you'll find loads of libraries, sample code and videos to get you started. 

If you want some books to read about the platform I'd look for books by Simon Monk. He has written some good Arduino primers, plus a few other fun books. 

Programming 

There is no such thing as the best programming language in the world, but I quite like C#. You can get a free C# book, plus a lot of teaching materials and sample programs, from here

If you want to learn some Python (and why not, it's great) we have a course of sorts here

3D Printing

My 3D printer is an Ultimaker. I call her Una and I made her from a kit a few years ago. You can find all my 3D printing posts here

Blogging 

Bloging is a great way to practice writing and maybe even make a name for yourself. I did a Rather Useful Seminar about blogging. You can find it here

Space Cheese Mining Takes Shape

I spent today building the First Year Assessed Coursework. Every year we implement a game as part of the course. The games usually involve Space and Cheese. This year we are doing "Space Cheese Mining". Players move around the board picking up cheese and stealing it from each other. I've built my implementation, added some AI players and turned them loose over 10000 random games.

Each game takes around 12 turns to play and the distribution of winners seems about right, although I think I'd try to avoid playing as red......

I make a new game every year so that people can't use "the magic of search engines" to find confusing (and probably wrong) samples on the internet. I'm looking forward to see what folks come up with on this one. We've got a "Cheese Battle" extension mode too.

Going Bananas for the 2015 C# Yellow Book

Every year I make a new version of the C# Yellow Book. And recently I've been putting something yellow on the cover. This year I thought I'd go for banana, what with it being custard last year. I took some pictures of a single banana, but these didn't end up looking to good to be honest. So I've gone for a bunch.

The text has been tidied up a bit and I've added links to the code examples that you can now get to go with the text. It will be going to print for our new First Year in a couple of days, and then I'll update the PDF on csharpcourse.com.

C# Yellow Book Code Samples

Due to popular demand (somebody asked me) I've added a whole bunch of code examples keyed to the C# Yellow Book content.

I've upgraded the Kindle edition of the Yellow Book (which you can buy here) to include references to the examples and you can download all the code from here.

Oh, and don't forget that you can also get our entire First Year programming course (slide decks, labs and assessed coursework) along with everything else from my C# teaching site here

Talking Teaching at the Institute of Physics

One of my slides....

One of my slides....

I went to Sheffield today. It's a nice enough train ride, straight from Cottingham. Even nicer when you have company (thanks to David and Emily for being in the right place at the right time).

The reason for the trip was a meeting entitled "Developments in Teaching Physics Students Computer Programming Skills", which had been organised by the Institute of Physics Higher Education Group. They'd asked me along to talk about my experiences teaching programming. Turns out I can do that.....

It was a really interesting day. Physics is a fantastic subject. And work in the field is greatly aided by a bit of programming expertise. There was considerable discussion about whether the expertise should be given in a programming language (for example Python) or using one of the popular lab packages such as LabView. Or perhaps a tool such as MatLab or Mathematica? Or you could just do things in Excel. Much to think about here...

I gave a little talk about the importance of the practical side of things, with emphasis on professional elements. I also mentioned a little framework I'm working on to help things along (of which much more real soon).

Everyone was really concerned to make sure that the skills taught were appropriate and useful, and given in a proper physics context. I think that in this company I'm more of a "means" person, with a focus on the process of producing a quality solution, where as the Physics folks are much more "ends" types, who see computing as a small component in a much larger picture.

Ether way it was a very useful and thought provoking meeting of minds.

 

Student Led Teaching Awards

I was very pleased to find out a while back that I'd been nominated for an award for Innovative Teaching in the Student-Led awards run by the University Union at Hull.

Anyway, tonight was the night when the winners were announced at a  posh dinner at Staff House on the campus. I wore my new suit (no-really) and we had a really lovely time eating and drinking between announcements. I didn't get the award, but I'm really honoured to have made it to top four.

Thanks very much to the students who nominated me and to the Union and University administration for for organising such a splendid programme. 

Time Travel in C#

Imagine if you could control time. Wouldn't that be useful? Especially if you were writing a program to manage artwork in an art gallery, and you wanted to test the part where after two weeks the artwork must be returned to the artist. You could start the program running, add an artwork, hop into the time machine and move two weeks forward and then check that the code works correctly. Of course this is impossible. But fortunately we don't have to do it this way. Instead we can build a bit of cleverness into the way that our program uses dates and times.

Normally a C# program will get a date from the system clock by using DateTime.Now:

artwork.DisplayDate = DateTime.Now;

This sets the display date of my Artwork to the current date and time. My program can then compare the artwork date with future dates to see if more than two weeks have gone by. The snag is that i have to wait two weeks to find out if the code works. So I make something like this:

static class DateSource
{
    public static TimeSpan Offest = new TimeSpan(0);

    public static DateTime Now 
    {
        get
        {
            return DateTime.Now + Offest;
        }
    }
}

This can be used in exactly the same way as the system DateTime class, in that it provides a property called Now which gives a date and time value. But, and this is the useful bit, the date it sends back has an offset applied to it, which I can change. If my program uses DateSource rather than DateTime I can move my program forward (or even backwards) in time simply by changing the offset value:

Console.WriteLine(DateSource.Now.ToString());
DateSource.Offest = new TimeSpan(days:14, hours:0, minutes:0, seconds:0);
Console.WriteLine(DateSource.Now.ToString());

The first statement will print out the current date and time. The second will wind the clock forward 14 days as far as my program is concerned. When we are testing I can add a "wind forwards" button that changes the offset so that I can test my code. I could even change the offset value in a test harness that does this automatically.

This is all part of my "build yourself a nice place to work" philosophy. If your program has to do special things depending on location, don't test it by walking around the countryside. Instead make a program that feeds test coordinates into the location part of the code.

Applications open for Summer Internships at Hull

If you're a student at Hull and you fancy spending 8 weeks in the summer getting paid to play with technology you should apply for a place on our Summer Internships programme. We had a very successful crop of interns last year and we want to repeat this. There are a number of different projects up for grabs and they all sound very interesting to me. The posts are open to students from any year, including first year students.

Students at Hull should check their inboxes for details of the programme, or get in touch with me and I'll send you a copy of the details.

Give Yourself Time to Fail

Restarted the teaching today. I did a show of hands in the first year lecture to find out how many people had started the coursework, which is due for completion in three weeks or so. I was pleased to find that pretty much everyone had started work on it. (or was claiming to have)

It is very important to start your computer science coursework as early as you can. This is because you need to have time to fail. By that I mean that there will be times when your program won't work and you won't be able to work out why. (this still happens to me by the way). In this situation you need time to be able to walk away from the computer and go back to it, which is a problem solving technique that works for me a lot of the time.

The other technique I use is explaining the problem to somebody else, or even just the wall. Half way through the explanation I hit upon the "broken assumption" that is the cause of the problem and can then go and fix it.

This is one of the things that makes computing different from lots of other disciplines. I don't think it is OK to work on the basis that you could dash off an essay overnight, but at least by the time morning comes you could have a bunch of words that may or may not be the right ones.

Try this technique with a programming assignment and at around 10:30 in the evening you'll find that your program doesn't work and you've no idea why. And you have no time to step away for a while and then come back and fix it. So start early.

What Price Protection in Programs?

I got a lovely question from one of our students today. He is presently working on our "Pick Up the Crew" game coursework and is using objects to manage the items on the screen. The question concerned protection of the data members inside the game objects. If you are writing software for a bank you need to be careful to make sure to carefully manage access to data inside your objects, since you don't want naughty programmers fiddling with account balances. But in a game you don't care so much about this kind of protection. There is nothing particularly important about where on the screen a sprite is drawn.

The questioner was asking if it is OK for a sprite to expose its position information in public data so that other sprites could find out where it is on the screen and check for collisions with it. This is a good idea from a performance point of view (if we are really worried about such things) because it provides quick access to the position information. But is it a good idea from a programming point of view? Should we worry about protecting data inside things like game sprites?

To me this is the wrong question. I don't like using public properties like this because it can introduce dangerous dependencies. If I decide to change the way that I manage sprite position I'm going to break all the other objects that make use of this information directly to work out whether or not they have collided.

From a collision point of view I reckon it is best if each sprite exposed a method (perhaps called CheckCollision) which could be used to see if it has collided with something else. Then if you change how the sprite stores its position on the screen you can just update the behaviour of CheckCollision so that nobody outside your class is affected by the change. There may be a tiny performance hit with this approach, but the chances of introducing bugs are much reduced.

Sortlisted for Student Teaching Awards

The Students Union at Hull has been running teaching awards for a few years now. I've been lucky enough to be nominated a couple of times in the past, and in 2012 I even managed to win an award. Which was wonderful.

I've just found out that I've been nominated for an award again this year. Thanks so much. The presentation dinner is in early May, I'm rather looking forward to it.

You can find out all of the details of this splendid initiative here.

Amazing fun fact: Rob Miles has in fact been nominated twice. It turns out that Robert Miles from the School of Languages, Linguistics and Cultures has also been nominated for an award. We are going to so careful that we don't both head down to the front if our names get read out.....

Rather Useful Seminar - What to do when you are stuck

The final slide....

The final slide....

Today David Grey and me gave a Rather Useful Seminar all about "what to do when you are stuck". I think everyone who was there got something out of it. You can find the slide deck here. If you want a quick summary, here goes:

  • Remember that everyone gets stuck on things every now and then (including me). The important thing is what you do when you get stuck - it's all about coping strategies.
  • The first step is owning the problem. You need to attack it. It will not solve itself, it will just end up owning you.
  • One way to own problems is to write them down. Rather than sitting trying to count how many things you've got to do, write down a list and then you can start dealing with each in turn.
  • Once you've written down the problem, decide whether you need to seek help. It is surprising how many students are shy of asking staff for help because they are concerned that we might think less of them, judge them for being stupid, or whatnot. We simply don't have time for this. What we want is as many students as possible to do really well. This is not because we might get paid a bonus. It's because that way we feel like we are doing something useful with our lives.
  • When you ask for help, rather than saying "I've no idea what to do, help me!", as for help with a plan. This can be as simple as getting a copy of the assignment highlighting the terms you're having the most bother with and getting them explained. Or it can be identifying a couple of next steps and asking which is the best one.
  • Break a problem down into chunks. Nobody does anything all at once. So you should find out what the intermediate steps are and then work on each in turn.
  • Give yourself time to fail. Start on work as soon as you get it. That way you can afford to walk away from a problem for an afternoon and then go back and solve it. If you are under time pressure you can't do this.
  • If you hit a problem coding, try to explain it to somebody else (or even the cat). If that doesn't work, take a break for a while and go back to it.
  • And finally, do what it says on the slide at the top.

Coding Conundrums

We've been running the "Wrestling with Python" sessions again. Each Tuesday we get together with some local teachers and continue the process of getting up to speed with the Python language. We've reached the point where we are having a go at programming puzzles. And it is proving quite fun.

I've put the "Coding Conundrums" up on the Python site so anybody can have a go. You don't have to use Python, in fact I'm sending the same puzzles around our department to give folks some programming puzzles to get their teeth into. I reckon that programming is something that you have to work at continuously if you want to get (and stay) good at it. Bit like learning a musical instrument.

I'm also starting to properly like Python. Most of my Python programming takes place in the forbidding environment of the FreeCad graphic design program. I've got no debugger, scant error messages and Python programs can be terribly "brittle", in that a small mistake can cause them to shatter into a million pieces. But I must admit I'm really liking it.