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

Moosaic Takes Shape

One of "Robert's Rules" is:

Any software development takes longer than you think, even if you allow for this.

Of course, having a day job as well has kind of hampered development...

So I've not finished the Moosaic program just yet. But it is looking quite tidy:

249244108
Coming to a setup program near you....

I've got the image download and the grid selection just about sorted, Now I just need to get the tile output done and we will be in business.

Prepare for Icon Attack!

231272342

I've been playing with the new XNA Express stuff which lets you write games using XNA. Great fun. I'm presently creating a little 2D shooting game which is provisionally titled "Icon Attack", where you fly "My Computer" into battle against massed hordes of Windows Icons, running in fear from the "Recycle Bin of Doom".

I've just got the first bit working, which is the moving icon starfield that will provide the backdrop. I'll keep you posted (quite literally) about how the development goes. Eventually I'll put the source up for you to marvel at.....

Live Writer Flickr Inkifier now available

I've finished writing the code for the latest Live Writer plugin. It lets you grab images from Flickr, annotate them with ink and then post them back. It also has a few image processing feature, including a "wild" thing which is quite fun. You can find out more here.

It's always the social issues that get you...

I've been playing more with my Flickr inkifier and it is now nearly ready for release into the wild. By that I mean that I've solved all the technical problems, but now I have to deal with the "social" ones.

These are the ones which give you the most grief as a developer because there are no hard and fast answers. When I wanted to add my plugin to Live Writer this was easy. Copy the example, read the documentation and away you go. But now I have to deal with users.

To post a picture to Flickr you have to login to the service. Fair enough. There is a lovely mechanism for this in Flickr which means that once a user has authorised my plugin with them they never have to do it again. But the plugin also has to remember some stuff about the login. So questions start to arise; "Where to I store the information?", "What do I store?", "How will the user interact with it?", "Do I store the data on a per user basis?". Ugh.  

 So, wrestling with all these issues has slowed me down a bit. That and marking all the programming resit exams and coursework. Double ugh.

Imagine that Live Writer Plugin

I've just made a plugin for Windows Live Writer which lets me easily post my Flickr pictures. There is a proper plugin available as well as mine, but mine does exactly what I want, which is quickly find the images and then add them to the post in the correct size. And anyway, I wanted to write my own to see how easy it is. So there.

One thing that I have learnt from the exercise is just how darned easy it is to string things together these days. Figuring out how to write the plugin wasn't too hard, and writing a .NET program to pull pictures off Flickr turned out to be much easier than I expected. So, without further ado, lets import some snaps:

 222860553
This is one of the dancers at the Imagine Cup party in Agra

222860621
This is outside the hotel lobby. I just love those white cars

222860583
And this is your room, after the room tidying faries have been round..

My First Post from Live Writer

This is my first post using Windows Live Writer Beta. It is a program which lets you prepare blog entries off line and then submit them from your computer. I might use it a bit because it is somewhat easier to use than the interface on my usual provider, and it lets me write stuff when I'm not connected to the internet. It found the settings of my slightly non-standard blogging service straight off the bat, and so far I'm impressed. Although I've not actually pressed the publish button yet.

There is also an API which lets you develop blogging applications

Of course, what I really want is a version of this program which runs on my Pocket PC. Perhaps later...

I suppose I'd better tell everyone

Every now and then you get a juicy bit of news which is of great advantage to those hearing of it. I've just got one of these and the urge to be a nice person and share it has got the better of me. If you are into teaching and computer science and stuff (and therefore in kind of competition with us at Hull I guess) you really should go and have a look here.

I reckon that it is a wonderful development that any computer science department should grab with both hands and run with.  We are soooo going to try and do just that...

Unhappiness is Green Cubes

greenBoxes
Not what I want to see at all...

I've been working on my webcast for next week. (if you want a way to speed up your life try doing a series of weekly webcasts - you'd be amazed how fast each one comes round).

Anyhoo, we are reaching the end, where I want to show my style and put some 3D objects on the screen in front of a funky background. The idea is to make a 3D version of the Snake game where the snake moves around with a constant value of Z in each vertex. I'm calling it "Snake on a Plane" in homage to the upcoming movie staring Samuel Jackson. The "snake" is going to be made of little coloured spinning cubes.  Why? I don't know why. I don't make the rules...

So I get my coloured cubes, put a green grass texture behind them and fire up the program. And all my cubes turn green. Wah. Don't want green cubes. Although they do look rather cool.  Tried lots of things to get rid of them. Everything except the right thing, which is to remember to turn the texture off. Ooops. Thanks to number one son for spotting this. Now I'm going to have to find a way of wiping that smug grin off his face.

If you want to take part in the last webcast and maybe win an imp, then register here.

Managed Code Archos

My portable media player thingy is misbehaving. It won't let me synchronise with Napster. This is a potentially serious problem, in that if it doesn't get to say Hi to mom every now and then all the protected content on the disk will stop working.  This is where the idea of renting access to music rather than actually buying it once and for all starts to come to bits.  I've surfed the internet and quite a few people have the same problem as me, but nobody knows how to fix it. I've been in contact with Archos technical support and they asked if the cable was plugged in correctly. Which was rather irritating.

Seems to me that every now and then a progam in the device goes loopy and tromps all over memory, corrupting things. Sometimes the machine will stop for no reason, or the screen will change colour without being asked. I can live with these problems, but if it won't play my music that is another matter. What they need is managed code. This is a layer between the vulnerable system and the program which is running. One of the jobs of a managed code environment is to stop a program from going bananas and writing into random areas of memory.  If this happens the managed bit just stops the program from doing any damage, like mum would stop you from putting your hand into the gas fire. 

It looks as if I will have to wipe the entire machine and start over. And then live in fear of it happening again with no guarantee that it won't. Or start buying records that I really like and stop renting.