Making Sample Data Can Be Fun

image

I’ve just released the first year coursework specification. We are going to be creating a system for a record shop which will track customer orders and suggest new records to buy. I think the only reason I went for a record shop was so I could call it “Vinyl Destination”, but that is by the by.

The program needs to be able to track huge numbers of records and customers, along with their orders. The problem is that, at the start, we don’t have any customers or orders, or anything. And anyone that thinks the way to solve this problem is to sit down and enter some details when the program has been built is very, very wrong.

I make the test data right at the start. I use a program to do it. All it takes is a few loops. Now, I could give the customers names like “Customer1”, “Customer2” and so on. But I can do better than that. All I need are some names to start with:

string [] firstNames = new string [] { "Rob", "Fred", "Jim", 
  "Ethel", "Nigel", "Simon", "Gloria", "Evadne" };
string [] surnames = new string[] { "Bloggs", "Smith", 
 "Jones", "Thompson", "Wooster", "Brown", "Acaster", 
  "Berry", "Ackerman" };

Here we have two arrays, one of first names and the other of surnames. I can now make myself a whole bunch of reasonable looking customers:

foreach (string surname in surnames)
{
    foreach (string firstname in firstNames)
    {
        Customer c = new Customer(firstname + " " 
                                  + surname);
        result.Customers.Add(c);
    }
}

This makes us a whole bunch of customers, from “Rob Bloggs” all the way to “Evadne Ackerman”. We can do something similar with the names for each of the recording artists:

string[] artist1 = new string[] { "Pink", "Flying", "Random", 
    "Singing", "Uptown", "Family", "Floating" };
string[] artist2 = new string[] { "Chicken", "Circus",
    "Banana", "Kitchen", "Groats", "Monkey", "Collective", "Pyjamas" };

I can combine the words to make random artist names.

string artist = artist1[rand.Next(artist1.Length)] + 
    " " + artist2[rand.Next(artist2.Length)];

This picks a random word from the first list and adds it to the second one (rand is just a random number generator that I use to make my test data). So I can have “Pink Pyjamas” and “Singing Groat”, among others. I do something similar for the track names, except that I have three parts. As you can see in the screenshot, this makes for some quite funny combinations, that liven up testing no end.

Stuck in Time

Untitled

Some time back I was given this clock, which I’ve had in my office for a while. Unfortunately I’ve found it impossible to use on a regular basis. Can you tell why?

Anyhoo, before it makes me too late (or early) for everything I’ve replaced it with this one, that I got in the Daiso shop in Seattle for a dollar fifty.

Untitled

Much better.

Actually Simon suggested the perfect solution to my clock problem. He reckons I should put the old clock on the wall behind me, and then view it via a mirror. I am so going to try that.

Surface Tensions

DSCF1039.jpg

So I got myself a Surface Pro. Took until Thursday morning last week, and a high speed white knuckle walk over to the Microsoft Store in Bellevue first thing to pick one up after I called and found out they had some stock (of course I couldn’t reserve it). In the end I took my 128G device, paid the lady and left. And I really like it. But that is not to say there haven’t been issues.

First up there is the finish. The Pro looked really nice when I first got it. Shiny and lovely. Unfortunately, unlike the granite like paint job on the Surface RT, my Pro looks as if it has been covered with icing rather than paint. I’ve already chipped lumps off the kick stand simply by brushing the device against the zip on my backpack. For someone as fussy as I am about my gadgets this is a major blow. I’m keeping it in a little “Surface bag” and babying it as much as I can, but I’m also anxiously checking it every five minutes for any more bits of paint that have dropped off. For a premium device which is sold at least in part on its toughness this is a bit of a let down to be honest. Not that it in any way affects how well it works of course, it is just that I like my new stuff to stay new looking. It helps with the subsequent sale on eBay.

Second there is the screen resolution. Now actually this is wonderful. The sharpness and colour depth are amazing. And there are loads of pixels. Too many in fact. If you look at the screen in “normal” 100% scale everything is teeny tiny. Microsoft have addressed this problem by setting the scaling for the display to 140%, and this makes all the icons and most programs look fine on the tablet. Of course things like Adobe products, which for no reason at all have their own display management, look stupidly teeny tiny, but that’s not the worst problem. You get that when you plug the Surface into an external monitor for a lecture and find that you are now viewing 1024x768 at 140% magnification. I thought I’d gone mad. Nothing fitted on the screen and everything was too large. Once I figured it out I then had the unpleasant realisation that I have to change the resolution and then sign out and back in again to fix it. Every time I do a presentation. If the system was smarter it would either realise that scaling up on a 1024x768 screen was perhaps a bit stupid, or perhaps it could allow me to scale different displays different amounts, so I could scale the tablet at 140% and the external screen at 100%. But it doesn’t do either of these sensible things. One answer, I suppose, is to just set the desktop to some lower resolution, but that kind of defeats the point of that gorgeous display. Everything works fine under the Windows 8 Metro display of course, but that is not something I use much.

Finally there are the Windows updates. This is not really the fault of the Surface itself, it is a more general malaise. Twice during the update process the system got stuck because it needed a reset to install updates and it didn’t get one. Twice I had the update process break and had to go in and delete all the cached update files and restart. Initially I thought I’d leave the machine to sort itself out, and was rewarded with the message that “This machine will reboot in the next two days” to finish installing updates. Of course, with an update reboot pending I couldn’t install any other software in that period and so I had to wade in and waste valuable chunks of my life watching progress bars. Wah. I know that updates are important and necessary, but there must be a better way than making the customer lose the best part of two days of faffing around before the machine can be made properly useful and stable. This is not just a Microsoft problem either, I dread turning my MacBook on because of the inevitable torrent of upgrades I’ll get (and don’t get my started about the 30 or so updates that are pending on my iPad applications). Perhaps the shops could apply updates to machines before sale. Perhaps updates could be applied behind the scenes. Perhaps somebody could figure out how to get updates out to machines without upsetting the user. We’ve had PCs for thirty years or so and we as still fixing them the same way. And it is awful.

And now the good news. The Surface Pro is ace. Goes like the wind. Runs everything I throw at it. Good for at least four hours of whatever I want to do on battery power. Weighs not a lot. And probably the only machine I really need.

Still Time to Enter the Imagine Cup

image

There's still plenty of time to enter the Imagine Cup. You could enter any of the competitions, including the one that I’m involved with, which is the World Citizenship Challenge. Every year I encourage students to enter and every year I’m amazed by what they come up with, and how much they learn from taking part.

If you are thinking of making a team and entering, or you’ve got a team, or you want some tricks and tips for working on your entry, I’ve jotted down some notes here.

Consider this, when you get that interview for that dream job, and they ask you the dread question “What have you done that’s awesome"?”, your Imagine Cup would make a very good reply.

Flying with Dutchmen

DSCF1054.jpg

Today it was time to pack up and head home from Seattle. I was on the same flight to Amsterdam as loads of other MVP delegates. Most of whom were from Holland. And had seen my memorable Kinect session last year at Tech Days Geek Night. And were quite happy to remind me of it again. I’m doing some sessions at Tech Days this year too. Some with gadgets. Now might be a good time to be very afraid. Or at least test the demos a bit….

My Next Car

Untitled 

Look at the size of that SatNav screen.

While we were walking around Bellevue Mall we noticed that Tesla Motors had a shop and one of their cars on display.

Want one.

The Tesla is an electric car powered by Lithium Ion batteries (the ones that they put in laptops and mobile phones). These give it high range (up to 300 miles) and amazing performance (0 to 60 in 6 or so seconds). They have a rather clever plan to put “Supercharge” stations over the country which are 200 miles or so apart. These can deliver a decent charge in around half an hour and should make it possible to drive right across America in the car. Because the stations will be solar powered Tesla are even offering free power top-ups for the lifetime of the car. I’m not convinced on that part, it will take an awful lot of sunshine to fill up the 40kWh batteries in even the lowest range vehicle, but you can’t knock them for trying, and I’d love for it all to work the way they say it will.

Untitled

I really fancy a car like this, even though it apparently doesn’t have an engine.

Of course it is far too expensive for me, and anyway I love my Nissan Cube, but should I ever be in the mood to drop 50,000 pounds or so on a new car, it would have to be one like this.

Untitled

Although I probably won’t buy the base model. (thanks to Peter for the line).

MVP Summit Party

Another day, another party with free food and drink. Sometimes I love my life. Anyhoo, today was the day of the MVP Summit party. It was held at CenturyLink Field, home of the Seattle Seahawks and Seattle Sounders FC.

DSCF1134_5_6.jpg

This is the view from the stadium steps.DSCF1148.jpg

This is the view from the Player’s Loft, where we met up with some Windows Phone team members and talked shop for a while.

DSCF1155.jpg

The view of the pitch. They had a soccer goal at one end and American Football goalposts at the other end, reflecting the dual use of the stadium.

DSCF1177.jpg

Oooh. Fireworks.

DSCF1220.jpg

Walking the pitch

DSCF1212_3_4.jpg

The hallowed (astro) turf.

DSCF1231.jpg

I may be wrong, but I don’t think that this is an MVP doing karaoke.

Thanks to the MVP Summit folks for a great night out.

Windows Phone MVP Pub Crawl

DSCF1081_2_3.jpg

Fancy a drink?

Tonight Desiree took the Windows Phone MVPs out for a pub crawl. And it was superb. We went to three places in all, starting at the Elysian Brewery Company where we got started with some great food and drink.

DSCF1028.jpg

After that we headed to Tavern Law, which had the most amazing “Speakeasy” vibe and more great food.

DSCF1075.jpg

Finally it was on to Unicorn for more drinks, and, joy of joys, pinball and video game action.

DSCF1098_099_100.jpg

Nothing improves a bar like a moose head. Or two.

DSCF1115.jpg

Pinball Wizardry

Desiree’s sister, who came along as part of her birthday celebrations (and was rewarded with a Geek Chorus singing “Happy Birthday”), told me that Desiree has got venues planned for the next 5 MVP pub crawls. I’m sure she has, and I hope I get to go to some of them too. Splendid stuff.

Travel Tips from Rob

DSCF0950_1_2.jpg

As a much travelled person I feel that now I can reveal a couple of my top travel tips.

Don’t wear brand new clothes to travel

I had this theory that my nice new deep indigo jeans would be both comfortable and stylish and send a message of quiet sophistication to the others at the summit. They sent a message alright, but not the one I wanted. I’d forgotten that some brand new clothes are apt to shed their colours on the wearer. When I washed my hands on the plane I noticed that my fingers had acquired a grimy tinge that was quite hard to remove. At each handshake with people I subsequently met I noticed that they were recoiling slightly as they discovered that I seemed to be suffering from what can only be described as “Blue Hand Disease”. Oh well.

Make sure you know what the switches in your hotel room do

My hotel room is splendid. Everything I need, comfortable bed and nice and quiet once I’d turned off the enormous fan heater in the corner. The bathroom is interesting though. It has two light switches. One makes a light come on. The other turns on a massively powerful heating lamp and also starts the bathroom extractor fan which makes a most impressive roar. When you are wandering around in a jet-lagged stupor at three in the morning it is best that you know which is which. Otherwise you will flick a switch and then immediately think you are in the middle of an alien abduction, which is quite invigorating in its own way, but does make it hard to get back to sleep again.

Out and about in Seattle

DSCF0855.jpg
Yes, they have painted the trees blue. No. I have no idea why…

After a sumptuous breakfast (thank you Siler Cloud Inn) I headed for the bus station and a ride into Seattle. The busses to Seattle travel through these amazing tunnels underneath the middle of the city and it has been my ambition to get some pictures of the drive through them. So I sat carefully at the front and took a whole bunch of blurred, unusable shots. Oh well. At least I have an excuse to try again some time.

The weather was a bit grey, but I managed to make my way to Pike Place market without getting rained on too much, which was nice. I bought a bunch of things at the comic book store there, had a browse around the craft stalls and generally had a really great time.

DSCF0885_6_7.jpg

Nice LightsDSCF0891_2_3.jpg

Anyone for fish?DSCF0894_5_6.jpg

Flowers

After spending a good long time in Barnes and Noble looking at stuff and trying very hard not to buy anything, and then dropping in to the Japanese store I caught the bus back to Bellevue and wrote some exam questions. Well, a chap can’t have too much fun in one day.

DSCF0932.jpg

After I’d written the questions I headed over to the MVP showcase, where 20 MVPs had been selected to show off what they have been up to. Lots of good stuff and a chance to meet up with folks I’ve not seen in ages. And there was beer.

I managed to stay up to 8:30 tonight, which I think is something of an achievement.

Flying Out to a Surface Pro

There is nothing quite like getting up at 3:30 am to catch a 6:20 am flight. Nothing. Still, the good news is that I am flying out to Seattle, one of my favourite places in all the world (another one is Cottingham, which is just as well really). First stop on the itinerary was Amsterdam, where I met up with Tom, Boss, Joost and a whole bunch of other MVPs who were all taking the same flight over to America. I wondered aloud if Microsoft actually had a rule about the maximum number of MVPs allowed to fly on one plane. If they do, we must have been close to the limit. The best bit of the flight for me was when the entertainment system on the plane rebooted, filling every video screen with a Linux penguin and boot sequence. The roar from the assembled passengers was quite impressive.

WP_20130216_004.jpg

One of the benefits of being crammed into a window seat with no legroom is that you do get to take pictures of the view outside. The lady at the gate was very sorry that she couldn’t find me a seat with a bit more space. But I doubt she was as sorry as I was. Anyhoo, the flight was smooth and speedy and I got to watch some movies, which was nice.

WP_20130216_005.jpg

This is a slightly more interesting view, once we had arrived. Richard and Steve from Black Marble were kind enough to give me a lift to the hotel (thanks guys). We went via a shopping mall, so we could dive head first into the American Experience as quickly as possible. Then it was back to the hotel. I unpacked then headed out for a walk.

The rain over here is proper rain. And they seem to have an inexhaustible supply of it. I went out for a walk in the stuff and managed to stay mostly dry. Note to self, buy an umbrella at some point.

The Microsoft Store in the Bellevue Mall was packed. I actually got to handle a Surface Pro, which was very interesting. Having completely convinced myself that I had no need of such a device I have discovered, having handled one, that I actually want one rather a lot. I was expecting something much heavier and thicker than the Surface RT, but it is actually rather svelte and doesn’t feel too bulky for a tablet to me. The screen is to die for (although perhaps not literally) and the whole thing works very well.

There were only two issues for me. Well three if you count the fact I really shouldn’t get one. Firstly they only had the smaller 64G devices in stock, and secondly the pen, while it works well and seems very responsive, feels cheap and flimsy to me. Having seen the lovely engineering that has gone into the Surface and the Touch Keyboard I was expecting the pen to be of a similar quality. Unfortunately it is more Bic Biro than Mont Blanc, which rather lets the side down.

The helpful girl in the Microsoft Store said they might be getting some of the larger Surface Pro devices in early next week. So I’ve got a day or so to talk myself into, or out of, buying one.

Then it was time for a quick McDonalds meal. I always have a Big Mac wherever I go, just to make sure that they taste the same worldwide. They do. After that I headed home and was in bed for 6:00 pm. My plan is 6 hours sleep, wake up, do some work, four more hours sleep and then off to Seattle for a wander round. On the way back to the hotel I, of course, took some more pictures.

DSCF0786_7_8.jpg

The food in Maggiano’s is lovely.

DSCF0802_3_4.jpg

I’ve always liked the idea of putting light in trees.

DSCF0814_5_6.jpg

Hmmm. Imax. I wonder what’s on?

Farseer Physics in MonoGame

screenshot_02132013_165926

I really like MonoGame. I also like physics. Particularly the Farseer engine, which works very well with XNA and lets you make things bounce around very nicely. I’ve had some success putting Farseer on Windows Phone, so today I thought I’d see if I could get Farseer to work with MonoGame. So I opened up my venerable old Destruction Golf demo from ages ago and just copied across the Farseer library and the code.

And it worked. Pretty much first time. Took me fifteen minutes in total. Amazing. The only problem was with the sound effect that plays when the ball hits the house. This wouldn’t play for some reason. But everything else seemed to move very realistically. If you want to add a bit of physics to your XNA then it is well worth a look. It is the older version of Farseer, but I kind of prefer that.

You can find the sample code for MonoGame Windows 8 here. You can find my video presentation about how the code works here.

Don’t Make the Recipe Static

DSCF0719_20_21.jpg

Today it was time to talk about static class members in the first year programming course. I always have problems with static. If you are not careful you start thinking that static means “doesn’t change much”. This is reasonable in real life, but not in C# programming. In C# programming static means “always present, part of a class and not of an instance”. At this point I thought an example would serve well, so we started talking about contexts where static would make sense.

Consider that you are implementing a system for a fast food store. You have a class called “Dish” and the system stores an instance of Dish for each of the items in the menu. A Dish instance holds the list of ingredients for the dish, the sale price, and the name of the dish. For example, there might be a dish called “Chicken and Chips” which held two ingredients (chicken and chips) and a price value (perhaps four pounds 50 pence). I asked everyone for some suggestions for static class members for the Dish class. Someone suggested that recipe would be a good candidate for a static member.

Not so. The idea of a static member is one that exists as part of the class. Which means that recipe could only be static if every dish was cooked in the same way (i.e. the recipe exists once for the entire class). Each dish needs its own recipe, so this must be a non-static member of the Dish class. However some things, for example the maximum and minimum price of dishes, the maximum number of ingredients that a dish can have all make sense as static members of the Dish class.

Simon has a sign on his office wall, “Consider the context”. When trying to work out what makes sense as static and what doesn’t, this is very good advice. And a good starting point is that “a recipe should not be static”.

Voice Music Upgrade

image

The slightly upgraded (i.e. more of it works than before) version of Voice Music is now in the Windows Phone marketplace. It now has improved help and full random play.  If you already have a copy you will get an upgrade soon. If you have a Windows 8 device and fancy selecting your music by spoken commands (works a treat over Bluetooth) then you can find the program here.