Very Useful Seminar

image

We did our Rather Useful Seminar today about presentation skills. You can find out more here. Then I went over to a student presented seminar about game development. This was run by the Video Game Society. It was excellent. I had to leave early as I had to go off to a meeting, but what I saw set out very well what we had been talking about earlier. There were some nerves, but one of my rules is that the day I don’t get a bit nervous before I go out before an audience is the day that I retire from this job. If you don’t worry about doing it right, then you might not do it right.

Great work guys, looking forward to the next one. You can find the slides and sample code here.

Visual Studio Express 2012 for Windows Desktop

image

The new Visual Studio 2012 Express is very nice to use. I’m even liking the funky dark colour scheme. But the fact that all you can create with it are Metro apps is a bit of a bind. However, Microsoft have now released Visual Studio Express 2012 for Windows Desktop. It lets you use the fancy new version of Visual Studio 2012, complete with SHOUTY MENU BAR, to create desktop applications in C#, C++ and Visual Basic.

Incidentally, if you want to put the menu bars back to how they used to be, Deborah will tell you how. She writes a really good Visual Studio blog with some very useful tips on the program.

Windows Dev Center Open for Business

image

I’ve just registered as a Windows 8 “Metro Style” developer. It went very smoothly, most of the stuff carried over from my Microsoft account. For the princely sum of 32 pounds a year I now have the ability to publish Windows 8 applications to the world. I wonder if the world is ready for a “Metro Style” Cheese Lander?

You can sign up here.

Cloud Gaming Debate at Platform Expo

image

If you’re around and about Hull tomorrow and interested in the games industry you might like to drop into the Cloud Gaming debate organised by Platform Expos. They’ve got Chris Deering, Founder of Sony Computer Entertainment Europe, Nick Thopmpson from KC, Mike Hewitt from O2 and Jiveen Lal from Hiscox insurance, who are also sponsoring the event. Also Ubisoft are bringing along a playable demo of Assassin's Creed 3 which will be well worth a look.

If you want to go along send an email to ian.archibald@wtchumber.com and he will sort you out a ticket.

C# Yellow Book 2012 Now Available

Yellow Pages

The latest version of the C# Yellow Book is now available for free download. You can get it here, or you can press the spiffy new short cut on this page.

There are a few changes. I’ve fixed all the mistakes that have been sent in (and probably added a few more). The section on Graphical User Interfaces now covers XAML rather than Windows Forms. And the text now mentions “The Wizard of Oz”

Control the Horizontal and the Vertical

Flying

I got an email today from a student looking for an interpolation technique to create smooth curves from a series of points. The reason he was after this was that he was making a game. His problem was that the technique looked a bit complicated and hard to implement on the target platform.

My advice in these situations is always “don’t sweat the complexity”. The simplest way to do this kind of thing is as a series of straight line segments. These are easy and quick to implement and should let you get something working really quickly. If the gameplay works OK, just stick with that technique and work with it. Remember that the player enjoying the game doesn’t know that you originally wanted to add curves. Only put the curves in if your game needs it.

If it turns out that lines would not be appropriate for your game theme, just change the game to one where lines do make sense. Remember that games are like “The Twilight Zone”. You control the horizontal and the vertical. The player is entering your universe, so you can define it as you like. Straight lines or curves, it’s all up to you. But start simple.

How to put files in sensible places

DSCF2695-Edit.jpg

I’ve been in the lab marking student work all day. I’ve watched around 25 or so demonstrations of software. Great fun. You might find it surprising, but I actually like this part of the job. Very hard work, but worth it just to see what students have done with the problem that we set. Every now and then I tell a student about something and they say “You should blog that”. And so here goes.

One of the things you often need to do is store a file from your program. You want to put the file somewhere sensible, for example in the user’s documents folder. If you want to find out where this is you can use an environment variable:

string docPath = 
    System.Environment.GetFolderPath(
System.Environment.SpecialFolder.MyDocuments); string fileName = docPath + @"\MyFile.txt";

The code above creates a string variable called docPath which refers to the documents folder for that user. It then creates a filename (remembering to put the backslash path separator in and use the string notation that stops it from turning into a control character) which can be used to create a file called MyFile.txt in that folder.

If you use Intellisense you can find lots of other special folders, including the ones for music and photos.

Event Today: Real Life Software Engineering

image

Anyone at Hull who fancies an hour’s break from coursework and revision today can pop along to a lunchtime event run by Robert Hogg and Steve Spencer of Black Marble. Rob and Steve are Microsoft MVPs (but none the worse for that) who have a lot (and I mean a lot) of experience of writing software for customers. If you want to hear some “Tales from Real Life” then you should go along to LTA in the Robert Blackburn Building at 1:15 pm today.

This event would be particularly useful for any First or Second Year students who want to learn more about the software development process.

I’ll be there…. taking notes….

C# Yield Return Fun

public static IEnumerable YieldFun()
{
    yield return 1;
    yield return 2;
    yield return 3;
}

static void Main(string[] args)
{
    foreach (int i in YieldFun())
    {
        Console.WriteLine(i);
    }
}

If you can tell me what the code above does, you understand how yield return works. If you can’t, read on……

In a C# program you can mark things as implementing the IEnumerable interface (to use this you need to have a using System.Collections; at the top of your program). This means the thing can be enumerated,  i.e. it means that I can get a succession of objects from it.

The best way to work through something that can be enumerated is by using the foreach construction, as shown above. You’ve probably seen foreach when you’ve worked through items in a collection such as a List or an array.  In the above code we are using foreach to work through the enumerable results that the YieldFun method returns. 

The code inside YieldFun looks a bit scary. The yield return keyword combination is followed by the thing that you want to send back for this iteration. In this case I’m just returning a different number each time. What happens when the yield return is reached is that the method stops at that point, returns the result and then, when the foreach asks for the next value, the method wakes up and continues at the next statement. The result of the program is simply the sequence:

1
2
3

If you want to programmatically supply a sequence of items to a consumer then this is  a great way to do it. 

What Computer should I get for University?

Seattle Museum.jpg

We got an email last week asking what kind of computer works best at university. Here are my thoughts on the matter:

Netbook

Netbooks based on the Atom processor are very cheap and great for web surfing, email and writing essays but they are a bit underpowered for the more demanding stuff like image editing and HD video. While you can use large tools like Visual Studio on an Atom powered Netbook it will not be a particularly enjoyable experience, particularly if you only have 1G of RAM in the machine.  However, they are great for taking notes, very portable and their batteries should see out a day on campus if you are careful. And they are so cheap you won’t suffer an enormous loss if you drop or lose yours.

Laptop

If you are buying a laptop I would go for at least a Core 2 of some kind. Machines based on the i3 processor are becoming affordable and are worth a look. If you are buying a laptop make sure that it has (or you can upgrade it to) at least 4G of RAM. If you want to write games with the machine it really needs a separate graphics adapter, those with built in graphics might work, but their performance will not be good. Take a look here for details of requirements to write XNA games:

http://msdn.microsoft.com/en-us/library/bb203925.aspx

Such a machine need not cost too much, I got an Dell Studio 15 with ATI graphics for around the 600 pound mark last year, and I’m sure things have moved on since then. Of course the snag with buying a “proper” portable computer is that it is properly heavy and scarily expensive to cart round with you.   This might mean that it gets left back at your house most of the time, which kind of negates the purpose of a laptop.

You should also look very carefully at the battery life. Bear in mind that although there are some charging stations on campus these are the exception rather than the rule and so a machine that can last all day is a good plan. I used to have a rule of thumb that I would take the manufacturers’ claimed life and halve it, so a machine that was supposed to be good for 3 hours would actually give only 90 minutes. However, I think things are improving a bit. My latest little machine claims 9 hours of use, and pretty much gets there.

Desktop

I’m in the process of returning to my desktop roots at the moment. I moved onto a laptop a while back because I loved the idea of having all my data with me at all times. It meant that I could pretty much work anywhere.  However, I can now have my data anywhere by using Live Mesh and Dropbox, and I fancy having a go with two monitors, so moving back to desktop makes sense. If you are buying a desktop now you should take a look at the new Intel “SandyBridge” I5 processor, which is not that expensive and provides a big leap in performance terms. Such a machine with at least 4G of ram and a 1T hard disk  and a reasonable graphics card should come in at around that magic 600 pounds (if you shop carefully)  and will provide a big leap in performance over a laptop of similar price. 

Some students have a great big hulking desktop at home and carry a tiny cheap netbook around during the day to take notes. This can work very well, particular if you use one of the cloud services (see backup below) to keep everything synchronised.

Apple

Apple seem to have figured out what makes something a pleasure to own and use, and then bottled it and sold it. All their machines run Windows really well, although the native OS X operating system has a lot to commend it and gives you access to wonderful programs like Garageband which come free with each Mac. And of course if you have a Mac you can write programs for the iPhone. 

I would place a slight question mark over the reliability and longevity of their hardware though. My MacBook Pro has been through two batteries, a power supply and a main board since I got it, and my little MacBook is on its second battery. I've bought machines from lots of other suppliers, Dell, Sony, Toshiba and Acer, and never had this failure rate with them.

If you are in academia make sure that you buy using the Apple academic discount scheme, you will save a little money but you will also get three years of Applecare warranty, which is well worth having. 

Software

Don’t forget software when you are pricing your systems. All our students get Microsoft Academic Alliance usernames shortly after they arrive with us and you can get Microsoft Operating systems and development tools for free from this:

http://msdn.microsoft.com/en-gb/academic/default

The only thing that you will miss from this is Microsoft Office, which you can get quite cheaply from here:

http://www.microsoft.com/uk/education/studentoffer/

If you want to try Linux I’d recommend taking a look at Ubuntu, which provides one of the best turnkey Unix experiences.

Backup

It seems that you have to lose a big chunk of work before you appreciate the importance of making backups of your data. One of my project students had their hard disk crash the night after they had just finished writing a very important report. Of course they hadn’t backed up the files…. 

These days, rather than remembering take a backup I use Dropbox and LiveMesh to make sure that files on my computers are all synchronised. During a working day I’ll probably move between two or three different platforms and these technologies make sure that the data on all of them always lines up. They are also provide browser based interfaces, so that you can get at all your important files anywhere you can find a web connection. 

http://explore.live.com/windows-live-mesh

http://dropbox.com/

The main problem with these services is the limited amount of space they offer. Live Mesh will give you 5G of online storage for free, with Dropbox you have to make do with 2G for free, although you can have more if you pay. However, this is not an issue for me. I don’t put any of my music or video on them, I simply use them to store “work in progress”, which for all the taught content and presentations that I gave last year only amounts to around 2 or so gig.

Insurance

If you do buy lots of fancy hardware do make sure that it is insured. Sometimes home insurance needs to be modified to cover expensive single items and if you move away from home you may need to get a policy of your own to cover your gadgets.

Final Words

Don’t spend too much on a computer. You don’t need a huge powerful machine to do our courses at Hull, actually most of the work (apart from 3D game writing) could be performed on a fairly basic system costing less than 300 pounds. We do have machines on campus which you can use, including some really powerful ones in the games lab which are available to students who need a lot of horsepower. Remember that anyone who tells you that you need the most expensive and powerful system they have is probably a computer salesman….

Hull Digital Windows Phone Fun

Hull Developers

I didn’t actually shout out “Look ‘Thoughtful’ Folks”, but it looks as if I might have done….

Had a great time at the Hull Digital Group meeting tonight. The topic for the night was mobile development. First up was John Connolly who gave a smashing talk on the pitfalls and potential of mobile development.

Then there was me. I gave a “Biased Overview of Windows Phone 7” where I extolled the virtues of the platform and very nearly showed my Windows Phone Twitter reader working. The audience was great, with some lovely discussion and very thoughtful questions at the end.  You can find the presentation and code files (including a version of that video game grate “Cheese Lander”) here.

DDD Manchester

DDD Audience

A great audience. Even though not all of them like cheese.

Today I got on the train to Manchester, did 90 minutes of standup with a broken voice and then got on a train back to Hull. I had to wear two microphones, that’s how bad my voice was.

Anyhoo, the sessions I did (Writing Windows Phone Games and Windows Phone Marketplace) seemed to go OK. Thanks to the guys at Appamundi for inviting me to speak.

I said I’d put the slides and sample code up on the net and, as a man of my croaky word, you can find it all here.

On the way out of Manchester I, of course, took some photos.

DDD Odeon

Print Works and Odeon looking good

The Wheel of Manchester

“The Wheel of Manchester” – it doesn’t half go round fast…

Free Windows Phone Developer Event Next Week

alt

Coming to a cinema near you. Probably.

Hot on the heels of the Windows Phone 7 Live training that we did last week in Bellevue,  Andy and myself will be presenting at a Developer, Developer Developer (DDD) event in Manchester next week on Thursday 7th October (seems appropriate).

If you want to find out how to get started with Windows Phone then come along to the free day’s worth of training. I’ll be doing two sessions on XNA for Windows Phone. I’ll also be telling the jokes that I wasn’t able to use in the Live Broadcasts…. Should be fun.

You can sign up here.

C# Fun with Pexforfun

image

pexforfun is fun. Especially if you like writing code. It gives you a mental workout, teaches you programming smarts and has a lovely test driven, puzzle powered approach based on “Code Duels”.

You are set the task of writing a program that behaves in the same way as some “mystery code”. You type your code into the browser (you get intellisense support and everything) and then hit the “Ask Pex!” button. Pex then compiles your program and runs it against the test cases for that mystery code. If your program works you get bragging rights and then move on to the next puzzle. If your program fails you get to see which tests failed, so that you can refine your code for next time.  You can log into the system so that you can track your progress through the puzzles or you can just turn up and have a go, like I did.

I’ve just done one puzzle and really enjoyed it. I think we will be using pex during our first year programming labs at Hull, it really is a nice way to sharpen your C# skills. Find out more here:

http://www.pexforfun.com/

Unblocking Files from the Internet

image

Sometimes you get a file from the internets, or in an email, which you actually trust. Thing is, Windows doesn’t. This can result in fun and games when you try to use this file or, if it is an archive, files from the archive.

As an example, I downloaded the TouchGestureSample from the Creators Club and I don’t want any messages about un-trusted files in Visual Studio 2010.

Solving this is actually quite easy (and best done before you remove the files from the archive). Right click on the item and then click Unblock to say that you trust this file.

(of course, if you do this with dangerous files it might not have a happy ending)

Quick Number Formatting in C#

IMG_2184

I’ve been playing with the Windows Phone accelerometer, and displaying results. Thing is, it gives me values which have lots of decimal places that I don’t really want. They make the numbers flicker in a way that hurts my head. What I want is a way to just display them to two decimal places.

I must admit that previously I’ve resorted to very dodgy behaviour at this point, such as multiplying by 100, converting to an integer and then dividing by 100 again. Must be my old assembler ways coming back to haunt me. Turns out that there is a much easier way of doing this in C# which is to use the string formatter:

message = "Accelerometer" +
    "\nX: " + string.Format( "{0:0.00}",accelState.X) +
    "\nY: " + string.Format( "{0:0.00}", accelState.Y) +
    "\nZ: " + string.Format( "{0:0.00}", accelState.Z) ;

This little block of magic gets the X, Y and Z values out of a vector and then displays them to two decimal places in a string I can display in my XNA program.

The key is the {0:0.00} bit in the format, which gives a pattern for the display of the first (and only) value to be converted. This pattern says a single leading digit and two decimal places.

If you want to do interesting things like put commas into numbers (so that you can print 1,234,567 type values) then you can do that too. You can find out more about how the format strings work in my C# Yellow book (subtle plug) starting on page 50.

Delegates, Events and Confusion

IMG_2283

Delegates and Events are really powerful parts of C#. They are also powerful confusing.  We can start off by making a new delegate type:

delegate void SimpleEvent () ;

This is a new type, called SimpleEvent. If we ever need to create a delegate that refers to a method that returns void and has no parameters, we can use SimpleEvent to do this. So, let’s do that. Here is our method:

void testMethod()
{
    Console.WriteLine("Test Called");
}

This method doesn’t do much, but it does tell us it has been called, which is a start. Now, to create something that refers to this method we can create a SimpleEvent instance:

SimpleEvent x = new SimpleEvent(testMethod);

This has created a delegate that refers to testMethod. We’ve given it the rather enigmatic name of x. We can make a call on this delegate if we want:

x();

Note that we have to treat x as if it was a void method that accepts no parameters (since that is the type of method that the delegate refers to). When x runs it will print out “Test Called”, since that is what testMethod does, and x presently refers to that method.

The name x is actually quite appropriate, in that when we call x we don’t really know what is going to happen, since it could be made to refer to any method. If it doesn’t refer anywhere we’ll get a null reference exception of course, and serve us right.

So, delegates let us create objects that can refer to methods we want to run. Great if you want to bind behaviours to events. (and this is where it starts to get confusing)

We can declare a delegate variable:

SimpleEvent eventList;

At the moment this refers nowhere (try to call eventList and we get an exception). But we can add methods that we want to be called when the event is fired:

eventList += new SimpleEvent(testMethod);

Now, when we do:

eventList();

- the testMethod is called. Wonderful. So let’s make this more confusing:

eventList += x;

This adds another item on to the list of delegates managed by eventList. The item added is the x that we created earlier, which refers to testMethod. Now, when we do:

eventList();

- the testMethod gets called twice (because when you call a delegate it works through all the methods that are presently bound to it).

If we want to unhook methods from a delegate then we can use –= to do this:

eventList –= x;

This would remove one of the calls of testMethod from the delegate, so that now if we call eventList it will only call testMethod once. And it works.

However, this works too:

eventList –= new SimpleEvent(testMethod);

I hate this. It confuses me so much. It looks like we’ve made a new delegate and minused (!) it from the list of events. There is some strong magic going on here which I really don’t like. What must happen is that the –= operator must go “Aha!, here is a delegate that references this method, I must remove one from the list of delegates”.

If x is the delegate that I originally created, it seems reasonable to remove that from the list, what confuses me is that you can also remove delegates by appearing to create new ones. I guess that this is because otherwise programmers would have to keep track of event references that they might like to remove later, but I still don’t like it.

Magic Numbers

Radio Humberside Front Door

What use is 5ebe2294ecd0e0f08eab7690d2a6ee69?

Actually, quite a lot. Particularly if you have lost the password to your website and you need a value to put in the password table.  Which is what I did last week.

We tell people never to write down passwords, but that still leaves us with the problem of what the server does to remember them. The server has to “write down” the password so that it can be compared with whatever the user types in to gain access to the site. 

The problem is solved using a technique called “one way” encryption. This takes whatever you give it and converts it into gibberish. It is called one way because the idea is that it is very hard to take the gibberish and work out what it originally meant. Sort of like the notes that I take during meetings, but more useful.

When someone logs in the password that they type is passed through the same encryption process and compared with the gibberish in the password file. This means that anyone stealing the password file from your server ends up with a file full of gifbberish which they can’t easily convert into the actual passwords that were entered.  This is why your sysadmin can’t tell you what your password is, because they don’t have that information. They can give you a new password though, because they can take some text and run it through the encryption before storing it against your username.

So, if I am stupid enough to forget a password I’m sort of stuck.  Which is where 5ebe2294ecd0e0f08eab7690d2a6ee69 comes in. The one way encryption that is used most is called MD5. If you take the word “secret” and run it through MD5 you get the block of gibberish you see above. I put that into my database in the right place and, hay presto, I was able to log in with the password “secret”.