Put some magic into your life

298266118
Now you can have one....

My all new "Magic Message System" is now available for download. If you've ever wanted a message system as good as the one in Computer Science at Hull University then you can have one... For now. I'm going to make it play videos and do 3D next. And I might not give that version away......

Because it uses Windows Presentation Foundation you will need either Vista or XP with .NET Version 3.0 installed.

So, what does it do? Well, it will display a slideshow of your Flickr pictures and at the same time read messages off an RSS feed reader of your choosing. We are going to use it on our plasma screen in the meeting area.

You can find it here.

One Day and Counting

298266118
Now I just need to add the movie playback...

My wonderful new Message Display program has now managed to keep going for a whole day. It is my first ever Windows Presentation Foundation (WPF) program and it is running on Windows Vista RC2 on the machine in my office all hours of the day and night.

Since the real thing is required to run for weeks, and any failures of the system will be very visible (and therefore highly embarrasing) I've embarked on this soak test. The program is running in "dog time" (i.e. around seven times faster than it should) so that the results are better than realistic. Later this week I might dare to go live with it on the big plasma screen.

Make your own jigsaws

249244108_ef4b99b2b5.jpg
My first ever test..

Moosaic lives! I'm about to embark on a new project and so I'm going round finishing off some old ones. And the first result of this is that you can now download my Moosaic program. This lets you create image jigsaws out of your Flickr pictures and then get them printed onto little bits of card. Fun for all the family and just in time for Christmas..

Find out more here.

Danger at 300 feet

Well, I'm back home now. The conference was great fun. You can see a video of me here.

The trip back was slightly enlivened by the landing process, which seemed to involve a bit more going up than I remembered from previous flights. Then the captain came on and said that a warning light had come on concerning the undercarriage as we were making our final approach. However, not to worry because he had done the aeronautical equivalent of bashing the dashboard of the plane and things were fine now...

Although it was a bit disconcerting to find all the fire engines lined up alongside the runway when we finally touched down...

C# 3.0 and Stronger Magic

Warning: This is a techie heavy post. If you are after witty prose and belly laughs then I suggest you look elsewhere (but then again - what are you doing here in the first place).

Just been to the presentation by Anders Hejlsberg about what C# will be doing in the future. I took a bunch of notes on the mobile phone which I've tidied up to post here (apologies for typos and spelling errors that got through):

Extensions

You you can add a method to an interface. Then any object that implements the interface can use the method. Extension methods are brought in with the interface by means of a using statement. You can add them to classes too. Serious potential for stupidity/confusion here but also a lot of power. What I call a Spiderman situation (With great power comes great responsibility).... You may end up leaving the impression that your extension is part of C# itself. I wonder if anyone has thought about colour coding the intellisense?

Talking of Intellisense (the bits in Visual Studio which suggest what items you might want to enter at a given point in the code) it seems that it is now part of the language design in that there is an inherent assumption by the language that it will be there for the programmer.

Var

The var keyword lets you simplify the deceleration process. The type of the thing that you are making is inferred from the type of the expression on the right. In this respect it smells a bit like the dim statement in Visual Basic, but there is a bit more to it than that. It underpins a general principle that you can manipulate items for which you have not specifically created a type, but from which the compiler can infer the required information to make sure that your code has integrity.

Lambda Expressions

Lamda expressions let you pass code as a parameter to a method. Sometimes you need to tell a method what to do. In C# you usually need to create a delegate type which you then point at a method which does the job. With a lambda expression you can put the behavior right in place. There is no need to make a delegate.  

Object Initialisers

Object initialisers let you set initial values during declaration of an instance. Can also initialize collections.

Expression Trees 

These are scary. They let me manage code as data. The compiler will produce the tree based on a lambda expression it is given. It ends up as a bunch of atomic actions which you can pass around as data. You can also modify the tree or produce one of your own from scratch. You can also compile these into IL or use them to make things like SQL statements. This is how we get our C# program code mapped into database queries for the Linq stuff.

Automatic Properties

Not sure about these, they just seem to save you typing. They let you create properties directly without needing to produce the get and the set right at the start. Must have both get and set, but you can make set private if you want a read only property. You can also put real methods in later.

Linq Database Access

This is perhaps the jewel in the crown of the C# upgrades. Query expressions use context sensitive keywords to map the query into method calls. This happens during compilation. Linq uses lambda expressions to denote the selection criteria. 

A query result can deliver a result as an  anonymous type (created based on the context of the result required). Because this class implements things like IEnumerable (so you can work through it) you can use the var keyword to create variables to work on the data. C# will be able to infer the required type. This means that you don't need to create loads of classes just to deal with query results.

There were some good code examples which show how queries are mapped onto code. And the other good thing is that if you download the whole thing and play with it yourself.

You're Using a Q1 for that?

Last presentation of the day found me at a talk about the use of ink in Windows Presentation Foundation. This was a lovely presentation, not least because of what the speaker was using to run all the demonstrations.

He was running big chunks of the show on a lowly Samsung Q1. This is an ultra-mobile PC which you can just about fit in your pocket (if you have a big jacket). He swore that, over and above some slightly fancier hardware for the pen, his was a very standard machine, with only 512Mb of ram. Notwithstanding these limitations it proved quite happy to run all the demos, including the 3D one at the end, as well as Visual Studio, all sitting on top of Windows Vista.

This left me determined to put Vista on my Q1 when I get home. I don't have the fancy touch screen stuff, but I do have an extra 512Mb of ram, which should be interesting...

The talk itself was about how Windows Presentation Foundation supports ink. Unlike the original Tablet PC, which was forced to shoehorn ink in alongside all the other user interface gubbins, with WPF ink is an equal partner as far as the programmer is concerned. Couple this with the fact that all the WPF pages are rendered as vector items (no nasty size dependence and infinite scalability) and ink starts to look very viable in the future.

Qn: When is a protocol stack not a stack?

Ans: When it is a "framework".

Had a very good talk about Windows Communication Foundation.

This is the means by which software shall talk to software in the future. And jolly good it is too. For me the most impressive thing is the way that they have used the features of C# (interfaces, attributes etc) to make it easy to set up connections and select the components that you want to use in any given situation.

When I was a lad there was much talk of protocol stacks. I even wrote a song about the ISO/OSI seven layer stack for one of my world famous lectures in rhyme....

But these days things have moved on, and now the talk would seem to be of "frameworks". I think these are a bit like stacks, but laid on their sides and with the ability to have extra bits (like security and compression) plugged in alongside.

It does seem very easy to link two process on the same or different machines and it looks as if this technology will make a lot of hard wraught code redundant as it takes away a lot of the difficulty in linking programs together.

Windows Presentation Foundation Fun

Just been to a presentation on Windows Presentation Foundation. This is the thing that I've been using to write a message system for the department. I thought I'd go along and find out how the grown-ups do it.

The answer is "Very well indeed". I was kind of pleased to find that my basic understanding of the way things work (describe how it is going to look in one file - the XMAL and what it does in another file - the DLL) was pretty much right. However, what really blew me away was how far you can take this stuff in skilled hands, and with the right tools.

It also opened my eyes to the potential for 3D and so the message system might be going to get even prettier. And something else that I'm going to find out more about is the statement that WPF is going to be available for mobile devices. That, my friends, is seriously interesting......

Customer Impressions

I love my job. Today has been uber busy. Updating the XNA presentation, giving a couple of lectures, attending a mid-semester review meeting with the second year (we had loads of students turn up - and some really good discussion about how we do what we do).

And acting as a customer in our Software Engineering project. At first I was not looking forward to this. We usually try to get people to do this who the students doing the work are not familiar with. I've been giving lectures to this group for a while, and in this respect I'm quite well known.

But for the project I have to be "just a customer". But actually it is quite fun. Some of the people who have come to see me have asked jaw droppingly sensible questions that I would not have thought of asking if I was doing the job, which is great. And I quite like being unhelpful and uncommunicative for a change. At least, I think it is a change......

I hate Microsoft

I had all the slides ready for my talk at TechEd 2006 in Barcelona. I'd even scheduled a presentation today so that I could preview the material to the students on our MSc course. Everything was ready. What could go wrong?

Well, what went wrong was that the Microsoft XNA team were too darned efficient for me, and released the second beta of the XNA Express yesterday. What's worse, they've fixed a bunch of issues that were irritating me and also made the Content Manager bit work so well that I just can't ignore it in the talk. I hate them all.

Because I have no intention of standing up next week and saying a whole bunch of stuff which is out of date or plain wrong it has meant that I've had to spend a big chunk of last night and this morning updating the slides and the sample code.

The good news is that the talk seemed to go OK (although I'm going to tighten it up just a bit) and that the sample game, "Hot Salad Death with Cheese" went down quite well.

287922640
Next stop Spain.

Web Tools to Ruin Your Life (and improve it)

One of the students put me onto something that is going to keep me amused during lunch hours for a while. It is called StumbleUpon, and it is an add-in for Firefox or IE which suggests funky web sites that you might be interested in. You assign a bunch of categories that you like and then press the Stumble! button. It then takes you somewhere you might find interesting. When you get there, you can rate what you see so that other people can find it later. Great fun and highly unproductive, in that I can see myself spending hours with this thing. Within minutes I had found this link. I'm sure there are thousands of others.

But if you want to use the interweb to improve your life productivity wise you should really take a look at del.ico.us. Stupid name not withstanding it is actually massively useful. Again, it installs buttons on your IE toolbar, but this time it lets you manage and tag web favourites that you find. When you find a site that you don't want to forget (perhaps one you Stumbled across) you press the "post to de.lico.us" button and it then lets you enter tags for the link. It also shows you a "cloud" of existing tags so that you can easily find related sites. Very useful. You can see my tags here.

Review : Applications = Code + Markup by Charles Petzold

I was kind of hoping that they wouldn't have it in stock since if they did I would make myself poorer. But there it was on the shelf. Browns in Hull had a copy of "Applications = Code + Markup" by Charles Petzold.  If you have any kind of history in Windows programming you will have come across Charles before. He wrote pretty much the definitive guide to programming Windows 3.1 way back in 1992 (I have a copy) and he has been writing new books about Windows programming ever since.

And now he has come up to date with the release of his book which tells you how to create programs which use the Windows Presentation Foundation (WPF) which is the way that you create user interfaces for Vista. I've been following the development of the book via his blog (which, although not as good as mine of course, is still worth a read).

I had kind of told myself that I would buy a copy if I happened to come across one, and on Saturday I found that Browns Bookstore in Hull had one in stock. And so I bought it. For the same price I could have got Lego Star Wars II for the XBOX 360, although I think I'll probably have more fun with the book to be honest (but I am a sad programmer).

I've been ploughing through it, but I'm nowhere near the end of its 1,000 or so pages. Charles Petzold writes very well, and I find the material very interesting. Some people might find the level of detail given a bit pernickety and distracting, but I really like it. And the other thing I really like is the approach taken.

I've been trying to make sense of XAML, (the markup language which lets you describe how your forms will appear to the user) and not having much fun or luck. As a programmer I want to get hold of the objects and control them programmatically, not by means of lots and lots of text. And although XAML lets me set up animations of bits and bobs (and you can have a lot of useless fun with this) as a person writing a program intended to do something I don't find the ability useful. Add to that the fact that the MSDN documentation is pretty appalling, actually telling you less than the IntelliSense in Visual Studio, and you have a recipe for frustration.

What the Petzold book does is put all the XAML stuff in the second half, and spends the first half telling programmers how to use the new user interface classes at a very high, and useful, level of detail. I've not reached the markup pages yet and I don't care. I'm too busy finding out how easy it is to lay out user interfaces which automatically design themselves when they load.

One of the very few things that I missed from Java when I switched to C# some time ago was the "GridBagLayout" manager. This was a swine to master, but when you got your head around it you could write displays which pretty much laid themselves out for whatever orientation and size of display you were using. In fact I missed it so much that when I moved to C# the first thing I did was write a layout manager.

With WPF something very similar to GridBagLayout is now available. And the way you use it is way better too. The book makes this clear and uses loads of examples to help you along the way. There are no screenshots though, which I initially found rather surprising. However, the good news is that this means you are encouraged to "code along" with the book, pulling up the examples and modifying them along with the text. This is a very good way to learn, and leaving out pictures means that the book can contain more text, which adds to the value.

In short, I think that this book will become as indispensable to the programmer as the earlier ones have, and if you want to learn how to do this stuff you should bag a copy. Amazon have it on a healthy discount which I wish I'd seen before I bought mine from a shop.

The Importance of Meaning

I've found another interesting blog post. This one is about the way that Service Oriented Architecture (where you create applications from components which expose what they can do in terms of services that they provide via a network connection) may not be the way and the truth.

This is because although you could provide a service called "Sell Widget" you can only use it properly if you have a good understanding of the meaning of precisely what it will do - which is not something that is guaranteed.

On the way to his conclusion the author provides a nice description of the archicture. Worth a read.

New York Times in WPF

If you want to read the New York Times for free, and in style, head off down here and download the Times Reader beta. This is a Windows Presentation Foundation (WPF) program which lets you read the newspaper on your Windows XP or Windows Vista device.

For the moment they are offering open access to the service, and it really works quite well. The environment itself is super duper, and a splendid way to see what WPF can be made to deliver.

Busy Busy

Had a fairly quiet Sunday. Managed to mow the lawns (not sure why, every time I cut the grass the darned stuff grows back) and finished off the Moosaic program (I actually got my free samples from Moo last week and they are quite neat - next I'm going to make a 100 picture mosaic and see what it looks like). The program is working OK and I've got an installer too, but I have a rule that I play with my programs on a bunch of different machines before I send them out into the outside world, so it will be a couple of days before you can have a go at making your own Flickr mosaics...

Oh, and I've been dealing with a steady stream of emails from people who came to see us yesterday. Thank you for all the kind words, and if you haven't had a reply from me yet, I will get around to you tomorrow. We will also post out all the C# books then too.

Green Green Grass of Google

Found an interesting blog post today. It is written by a bloke who works at Google (lucky chap).  If you are interested in the business of Software Engineering you really should read the post (and all the ensuing comments). It will take a while (I spent a whole lunch break reading it) but it is worth the effort.

If you think that things like computer programming are not prone to fashion and ideology the whole discussion should sort you out good and proper....

The Madness of XAML

Spent a whole evening achieving virtually nothing. I'm writing a little program for the plasma display in our new, spiffy, meeting area in the middle of the department (if you think that this means I'm a lot better at starting projects than finishing them- Icon Invaders, Moosaic etc etc then you are probably right - but this one needs to be done pronto and I'll get round to the others later).

Little know fact: Pronto was Tonto's younger, and much more punctual, brother.

Anyhoo, I'm using WinFX which is very nice. Got the latest versions of .NET 3.0 and all the trimmings and I can make swooshy windows now. I even managed to figure out how to read the RSS feed that is going to provide the data source for the display, and unpick the data from it that I want.

Then I try to put messages in the WinFX containers that hold my text. Now I'm using my usual learning technique here, which is to use Intellisense and MSDN and not read any books. Bad move. Simply couldn't figure out how to get text onto the control. Unlike old style windows components, which have a Text property, WinFX is much more complicated. It has FlowDocument and Paragraph and Block and all kinds of paraphernalia. But no Text property. After a lot of messing about I found that there is an InLines property which does pretty much what I want and lets me add strings of text to the display. Hurrah.

But the really good news (which probably makes the 90 minutes of cursing and swearing worthwhile) is that it will do all the formatting for me using Xaml cues in the string to lay out the text.

Which means that whilst it has taken me ages to do the easy bit, the hard bit should be really easy. If you see what I mean.

I'll post the program in source form once I've got it working.

But is it a bug?

I noticed a little "foible" of Windows when I was writing my Moosaic program. Windows provides a lovely way that you can load an image into a program. You just go:

Bitmap b = new Bitmap ( filename );

This goes off to the filename and gets you a shiny bitmap which contains your picture. However, it also leaves open the connection to the file, so that if you try to delete the file you get an error saying the file is in use. I don't think that it is. I've just read an image from it, that is all.

This is rather frustrating if you want to reuse a temporary image file. In the end I had to use a stream to read the file, which I could then properly let go of..

StreamReader streamReader = new StreamReader( filename );
Bitmap b = new Bitmap( streamReader.BaseStream );
streamReader.Close();

This is messy, but works in that the file is released. I'm wondering if I've found a bug or a feature...