21st Century Displacement Activities

In the old days, when I had a bunch of marking to do I would go off to the union shop and spend ages choosing a suitable red pen. I'd try each of those on sale at least once and then carefully weigh up the heft of the pen, the quality of the ink colour, the feel of the writing action and so on. I could usually pass quite a while doing these activities, not actually doing anything towards getting the marking done, but feeling good about the fact I was in fact making progress. When of course I wasn't.

Spool forward a few years and I can't do this any more. Some of the stuff doesn't use a pen at all, everything happens on the computer. But I still need my displacement activities. Fortunately the computer, if it is nothing else, is a wonderful source of potential displacement.

I've been marking stuff submitted via Class Server. This has the option for the marker to create six pre-formed text items which can be inserted into the student comments. Thing is, six is nothing. I've got loads more than that. Loads. It really hurts to type the same kind of thing over and over, but I need more than six. More like sixty. So, I built PasteMaster to do this for me. It took me around an hour to build, which is probably longer than I spent choosing pens, but I think it is worth it.

PasteScreen

You can type the comments into the text fields and then when you press the button they are inserted into the block at the bottom. You can edit the text at the bottom and add new bits, and everything you add is also placed in the paste buffer, so you can drop the whole report into any windows app. It remembers the comments from last time you ran it, and there are 6 pages of 12 comments that are colour coded and you can flip between.  I managed to set up a page of comments about each of the deliverables I was asking for, so that I could pull out pre-formed bits where appropriate and save myself quite a bit of typing.

(I was going to add a "randomise" button which would pull a comment out of a textbox on each frame and make a random response, but I thought this might be dangerous....)

Anyhoo, it works a treat and saved me a fair bit of typing. Of course, I could have used Notepad, but I think it would have been a bit harder to do and I would not have had the fun of making Pastemaster work.

If you fill out forms with pre-formed responses, or you do the kind of marking that I do, you might like a copy. If so, let me know.... 

New Soul

One of my favourite books since forever is "Soul of a New Machine" by Tracy Kidder. It recounts the story of an attempt by a bunch of engineers to build a new microcomputer for an ungrateful company.

Whilst the technology described is now very elderly (the book was originally published in 1981) the story of what drives engineers to create is still bang up to date. So, get the book and read it. Even (or perhaps especially) if you know nothing about computers.

Then spool forward 26 years in time and read Dreaming in Code. I've not got it yet myself yet, but a review which compares it to "Soul" is good enough to get me onto the Amazon site and flashing my credit card.

Code that sucks

I'm writing some background stuff for the .NET Micro Framework book. We've been working on the final project, which we want be a mobile robot of some kind. I suggested a Micro Framework controlled vacuum cleaner, and so today I started work on the emulation environment for it.

The idea is that we can simulate "pixel dust" on the floor and the "virtual sucker" will sweep this up and collect it. Our vacuum will have a dust meter which will allow it to tell how much dust is being collected and the name of the game will be collect as much dust as possible whilst avoiding crashing into the "virtual furniture". Then we are going to try to put exactly the same code into a real roving robot and see what happens, Great fun.

It also means that I can write properly factored, well commented code with methods called "doSuck". Wonderful.

Pitch me a Snake

I've spent a very happy day in the labs marking student work. Normally I hate marking. Exam scripts send me into a cold sweat. But this was much more fun. Rather than dead trees I was looking at live code. Each of our students in the first year was given 15 minutes to pitch their Snake game. And there have been some super ones. We are going to open up the "wherewouldyouthink hall of fame" and put some of these programs up there for download. Great stuff.

Next semester we are going to take the snake game and move it onto an XBOX. And I reckon we will be the first people in the world to do this in an undergraduate course at first year level.

Ed Gibson is "The Man"

Today we went up to Bradford for a rather special talk. The folks at Black Marble arrange seminars for IT professionals (you'll never guess who's giving the next one) and today they had managed to get Ed Gibson over to talk about Computer Security. Ed is quite a chap, an ex FBI guy who is now Microsoft UK's chief security advisor.  So a bunch of students and myself boarded a magic bus to Bradford.

We were lucky enough to meet up with Ed. before the talk. Thanks to my super advanced planning I managed to get everyone to the venue around 90 minutes early, and so we had plenty of time to sit around a roaring fire in the hotel bar and chat. Ed turned up and the first thing he did was buy everyone a drink. My kind of guy.

Then, after some superb sandwiches courtesy of Black Marble it was time to get down to the serious business of the evening. And it is serious. Ed has been there, done that, and told us some truly scary stories. For me the most interesting thing that emerged from his talk is that the computer fraudsters don't want your bank details. They want your bandwidth. If they can get enough machines on the net under their control they can pretty much take down any server, anywhere. Unless you pay them big money.

At some point we will have laws that extend far enough to catch the perpetrators and enough systems out there hard enough to resist the attacks that can turn your home PC into an agent of the bad guys. However,  until then the rule has got to be keep your system up to date. Don't think of computer crime as a "soft" crime with no real victims. The people who do it are in there for the cash, very organized and totally ruthless.

Ed made some good points on a broad canvas. The speaker that followed him zoomed right down into the low level detail. He showed how breathtakingly easy it is to attack a system. One of my programming rules is "build yourself a nice place to work". What I means is make sure that it is very easy to create, build and test the systems that you are writing. It never really occurred to me that hackers would do the same.

We were shown a tool which used SQL injection (basically a way of putting database commands into the text you feed into a web page) to stripmine entire company databases. I knew about the technique, but I never thought there would be such advanced tools for this kind of thing. The next thing that we were shown fair took my breath away. It involved changing the way that the .NET Framework itself works.

Imagine that a developer has got some permissions set on a program. And they want to stop users from pressing certain buttons on certain screens. The Forms library that ships with Windows will do this for you. With a simple property change you can disable a button. If the button is disabled it turns grey and the user can't press it. Job done.

Unless someone changes the guts of .NET so that this property change no longer works. By just changing one particular byte in the right library file a nasty person who has access to your machine can make every single button work all the time. So simple, sooo scary.

Admittedly you'd have to do something rather stupid to let someone else run their program on your machine in the first place, but the result of this is that even securely written code can now be totally banjaxed by being hosted on a corrupted system. Amazing stuff. Simple yet brilliant. And a very worthy follow on to the talk from Ed.

This was a superb evening. Kudos to Black Marble, Ed and his associate (who's name I've forgotten I'm afraid). All the students had a great time, with some pretty deep conversations on the bus on the way back. This was the first Black Marble event I've been to. It will not be the last...

And with that, I'm just going to update my virus scanner...

.NET Micro Framework Book

I'm writing a book. I'm very excited about this. The schedule is deeply scary, in that we hope to have the bulk of it completed by the end of January next year, but then again if you don't set a deadline you don't know when you are late. Anyhoo, myself and Donald Thompson of Microsoft are writing a programmers guide to the new .NET Micro Framework.

This is a new embedded platform which Microsoft have been working on for ages (it is what powers the Microsoft SPOT watches). For me it is a terribly interesting because it means you can write code in a high level, managed, environment using C# and then run it on a device the size of a postage stamp which costs pennies to make.

I am anticipating that it will do amazing things to the world of embedded development, as it makes it much easier to write code and put it into any kind of tiny system.

I've had a .NET Micro Framework microsite on my pages for some time. We've just set up a site for the book and we will be posting sample chapters and the contents for comments soon.

Robs Laws

I was talking in a Software Engineering lecture today about "Rob's Laws" amongst other things. I think it is time these were finally written down.

  1. Any given computer is too slow. No matter how fast you think it is when you get it, after a while you will think it is too slow.
  2. Any given project will take longer than you think. Even (or especially) if you allow for this. The only exception to this rule is a project you won't get paid for, or one where you have massively misunderstood the requirement and are therfore doomed.
  3. A program that is useful will have bugs in it. The only programs that can be proved to be correct are too small to do anything that you might want.
  4. A highly successful, fully working, system which contains hardware components will just about always have a massive "kludge" somewhere in the middle of it. This is the bit that has to be there, otherwise it won't work. Nobody will completely understand why it has to be there, or what it does, but they do know that if you take it out the system stops working.
  5. A customer will never ring you up and tell you their program is working fine. Never. If the phone rings, it is always bad news. Silence either means they haven't got round to testing it yet, or it is working fine. At the point where you think it has gone quiet for long enough for it to be definitely working the phone will ring and they will tell you they've just got around to testing it and have found something they don't like.
  6. As soon as you assume something about what the customer wants you are doomed. For sure.

Dragging down Vista

Well, today's the day. I've been involved in the Connect trials of various versions of Vista - even posted a bug report or two - and this morning I got my reward in the form of a free copy of the new operating system. All I had to do was haul my browser over to the download site and grab it. Just me and a few million other people.....

Well, after a few fits and starts during the day I've managed to get a whole DVD's worth of the new magic and I'm starting to install it. I've been generally impressed with the Vista experience and I've been looking forward to getting hold of the genuine article. I was a bit scared when the screen came up with "..this upgrade may take several hours." but as I write this my media PC is running the final version.

Just in time for me to go to bed....

Man with two brains

I've been acting as a customer in our software engineering practicals. Student companies have been interviewing me to find out what is really required, and I've been delightfully vague and unhelpful. Not at all like me, but probably a good learning experience for them.

Thing is, I'm also offering a consultancy service where, for the princely some of 2% of their overall mark, student teams can have a few minutes of my time to comment on their designs. What surprises me is how few teams have come along for a chat, for the potential improvement in the marks this is very good value.

However, one of the teams for whom I'm the customer is coming to see me tomorrow. This means that I'll be commenting on the behaviour of myself, and giving advice on how to deal with me to find out what needs to be done. Very strange.

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...

TechEd Update

Yesterday and today have been a bit of a blur. I've been to more sessions. Marvelled at the .NET Micro Framework, revelled in the Robotics stuff and been very impressed with the RSS feed talk this morning. I've found time to take a few more pictures too, which is always nice.

293325482
Rather a good sunrise

293326487
Even got the moon in this one

293326214
The Expo centre

293325756
The exhibition floor

293325574
MSP's from around the world.

293325902
If you have met me you will understand the humour in this picture.

There are some more on Flickr.

Tomorrow I give my session. Wish me luck.

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......

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.

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.