Rule 1 of samples. – They should be helpful.

I was looking forward to working with the new WP8 development environment. So after the delays in releasing the WP8 SDK and taking care of the extra needs to run the WP8 emulators, I was glad to see how easy it was to upgrade my WP7 apps to WP8. There was a lot of work required to upgrade from WP7 to Win8 and it was looking like the transition to WP8 would be a similar problem. Win8 had a number of similar features, but did require a lot of extra care. Pivots and WrapPanels did not exist in Win8, the way languages were handled also changed. When I was able to run the WP8 SDK, it was a one button click to upgrade the WP7 code to WP8 and no issues were found. Though the emulator took its’ time starting up and shutting down, the code actually seemed to run faster.

So now that I was comfortable with the new environment, it was time to start writing WP8 apps. I am still on the fence as to whether I should go pure WP8 or continue to write WP7 apps because of the existing users. There are a few tempting WP8 features, but so far most of what I need is in WP7. It would be interesting to hear, other than the tiles, what WP8 features actually make it into WP7.8.

One of the features I was interested in playing with was the LongListSelector in the Phone Toolkit. After downloading and installing the Phone ToolKit and the samples, I found a number of other tools that looked very interesting. When WP7 came out, must of my learning was from disecting examples posted by others, so I dove into the Toolkit. Unfortunately, I was not impressed by how they created their examples. Rather than a collection of samples, it was a monolithic solution that contained samples for WP7 and WP8 and included both the VB and C# code. The code to rebuild the toolkit and the samples were also melded into the solution.  It took a bit of digging to try and work out the structure of the program. The solution is great for demonstrating the features of the Toolkit quickly, but it is extremely poor way how to use the features in code. The actual code for the feature is easy to find, but there is a lot of ancillary functions that are needed to make it work and they are mixed in with all the ancillary functions of the other features.

There is also a bit of cute code. Stuff that is remeniscent of my APL days when you tried to cram as much functionality into a single line of code as possible. Or use of some of C# cryptic features. My favourite in the LongListSelector was this gem

public static string GetRandomFirstName() {return (_rnd.Next(2) == 1 ? _rnd.Next(CensusFemaleNames): _rnd.Next(CensusMaleNames));}

If these are to be examples, then the procedure should span several lines and a standard if {} else {} used. The frustrating part is that the above code works in the sample, but not when the module is copied to a new project and the only change was to the NameSpace. ;-(

So which approach to use to make a reasonable working example to build upon? Copy the sample and try and hack out what is not relevant? Start with a clean WP8 solution, add the obvious relevant modules and add the missing pieces as the compiler complains? Since it is not always obvious what is and is not relevant, I pefer the second approach.

So when it comes to creating samples, I prefer the Gene Simmons approach, keep it simple and lose the fluff.

So it looks like the PH Factor is still in effect. After posting to PH, I came across a simplified example by Microsoft’s Rohan Thakkar that was a simple demo of the People Hub using the LongList Selector  The Dev Center has other good AND SIMPLE examples.

John Marshall… Visio MVP

Published by johnvisiomvp

The original Visio MVP. I have worked with the Visio team since 1993

One thought on “Rule 1 of samples. – They should be helpful.

  1. I completely agree with you! If you’re going to do examples, you’re hoping (maybe expecting?) people to actually read/use them! If they’re dependent on other piece of code and that’s dependent on other pieces which are dep….you get the idea…then it’s just not reusable let alone, convoluded to follow! Good on you for trying to follow those, but I completely understand your frustrations!

Comments are closed.