Tearing down the old blog

I have decided to make a clean break from the old blog and start anew with all new content and writing.  I may post some of the old articles here, but most of them were really, really out of date.  Time to clean house and start over.

Happy New Year 2015

I will be editing and posting the most popular linked and read articles from the past several years. I will be removing posts that were specific to my previous company, or have now been replaced by newer technologies. I had a lot of Windows Phone 7 specific stuff that doesn’t work in Universal Apps, so why keep that content up?

Always be improving, or you are accruing technical debt

How healthy is your company?

I spend a lot of time working with companies to help them change strategy on their technical products. Most of the time they initially view it as just “moving to the cloud”, or “updating the software for scale”. But in almost every case they are radically changing their future by doing so, they just don’t know it yet.

Some of the companies I work with are going into this knowing full well that they need to make a change or become obsolete. Many are following industry trends in an attempt to be a first mover in their particular field. Others are embracing change as a way to be more profitable.

Where is your technology in your company? Is it moving to adopt with the future? Or is the last time someone hit File|New Project over a decade ago?

Adapt, Adjust, Overcome

When I was in the Army they used to through all sorts of crazy training scenarios at us. If the scenario stayed the same more than twice people would become bored and just sort of go through the motions. But the instructors rarely allowed that to happen. They would always throw in some little twist to keep people on their toes, and to make sure they learn a new lesson from an old training exercise.

I think far too many software companies I go into are just running the same exercise over and over. Sprint #142 we will do the following work. We will test it here, we will ship it there. They have no part of their team looking at what could be the next big disrupter in their field.

Now you shouldn’t fixate on that disrupter, but you need to know what it is. I personally follow OS development (open source, and academic), language trends, mobile phone trends, compiler changes, app design trends, and the list goes on and on. Why do I follow such a broad range of tech? Well, truth be told, I am just a geek who loves tech. But that also makes me good at my job as a Technical Evangelist.

But really the edge it gives me when I walk into a company is amazing. I can talk to the company CTO about trends that are in a similar vertical to his and ask if that is something happening in his. Sometimes they were not even aware of the change taking place, other times the change scares them. Change is constant in the tech world. Embrace it. That doesn’t mean starting over every year. But every 5 years you should look at your current tech products and ask yourself, “Would I build the same thing now that I built 5 years ago?” Would you change languages, tools, features, analytics?

If the answer is yes to any of those, what are you going to do about it? You can bemoan that the choices are made and you have no budget to rewrite it all. Or you can get started spending 10-20% of your time and budget on building V.Next of the software. ALWAYS BE IMPROVING. If you are not improving your system, it is dying. Every month with no new features, no new insight into how the tech is serving customers, is a wasted month. Those months add up. Pretty soon you are 10 years down the line and your only choice is to hit reset and rebuild from scratch. Technical debt can pile up until you have to declare bankruptcy.

All companies are software companies

I knew this before I started at Microsoft, but it is SO much more apparent to me now than ever before. A short list of the industries I have touched since joining Microsoft.

  • Financial
  • Industrial Manufacturing
  • Industrial Automation
  • Customer Relationship Management
  • Point of Sale
  • Chemical Manufacturing
  • Entertainment
  • City/Government Planning
  • Architecture
  • Mechanical Engineering
  • Power Generation
  • News / Reporting
  • Higher Education
  • healthcare

Every single one of them is really a software company. They may not see it that way, but what they are selling cannot be done without the use of a LOT of software today. I asked one CTO who thought tech was just a nice thing to have, “What would happen if I took away every PC you have in your factories for a year?” He sort of turned pale, and the replied nothing would happen after just a few days we would be at a total stoppage. Prior to that meeting he had put technology as “not important” for the companies future. Afterwards he said he was going to be seriously looking at where tech meets his manufacturing and how they can get it moving forward again.

If you are not growing, you are dying

Always strive to be growing in everything you do. Personal life and work life. I personally don’t ever want to think about what happens if I lose the will to keep learning and growing as a person, or if I decide to stop growing as a technical evangelist either.

Kids don’t want PC’s, doesn’t look good for future

This will not come as a big surprise to many, but I think maybe my reason why is a little different than most.  Microsoft is missing that gateway device for kids that are too young to get a PC or a Windows Phone.  Something like the iPod, iPad or Google Android tablet device.

Kids get these non cell devices first

This is usually a birthday or Christmas present, and they almost immediately switch all present requests to gift cards for their new ecosystem.  Of course kids don’t call it that, they don’t know they have just made a major decision point in tech for their future.  They just thought it was cool they had the same device as their friends.

Most of these devices are bought (rather then rented per the current US cell phone market model), so that makes them unique.  Many parents are price sensitive to giving an 8 year old a piece of technology. 

In my kids own classes during middle school the device of choice was the iPod.  These kids would literally spend $100’s in gift cards on music, movies, TV and apps.  Now normally you would think that is just what kids do, they spend money on short term thing like that.  But now the bigger decision comes when they hit about 13 and go to get their first cell phone.


But I already have all my apps and music!

Talk to any of these kids about what type of phone they want and they will immediately gravitate to the one where they have their apps, movies, etc.  One of my daughters friends said she has over $1000 “invested” in her iPod, so of course she wants the iPhone (duh for me even asking!).

These kids don’t care about tech, they care about what they already know and have apps that they don’t want to lose.  Suggest to one of these kids that they get a Microsoft Surface and they will freak out on you in a hurry.

Look forward a few more years, and it gets worse

Now my eldest daughter is an upper classman in High School and is thinking about college.  Even though she uses a Laptop PC for school today (supplied by the school) she wants to get a Macbook when she goes to college.  I asked her why and she said that all her music, movies, TV will just work with it.  No hassle in figuring out how to get it to Windows.  She could care less about Word, Excel, etc.  She wants what will work with her existing stuff.

Microsoft Zune – oh how I miss you

This leads me back all the way to Microsoft Zune. I seriously think Microsoft killed it about three years too soon.  At this point in the product cycle Microsoft has NO device for these early kids. 

Zune was that device, it even had a great ecosystem around desktop stands and ways to get music into the home through docks, etc.  None of the current Windows Phone devices have broken that barrier yet.  There is no standard connector for all the phones for any manufacturer to even make a dock for Windows Phone.  The market has gone more Bluetooth powered in the past few years, but having a dock is what made all those hotels buy alarm clocks that you can plug an iPod / iPhone / iPad into.

Microsoft Surface is not that first device

The Microsoft Surface is too expensive for most parents to buy for their kids (when they can get a Nexus 7 for $199, or an iPad Mini for $329).  I do think we will see more of the first devices for kids be tablets rather than iPods, but Microsoft is still pricing themselves out of that market.

Go to Universities today and look

I teach at schools around the world periodically as a part of my job.  I am always confronted with 90%+ Mac laptops in the classrooms.  Many of them are running Windows in a VM for “antiquated classes that don’t have Mac software”. 

This looks bad for PCs, and Microsoft in particular, in the years to come.  As those kids get to jobs and start the BYOD revolution they will not want a PC or Windows. 

The only way I see this changing is if Microsoft can break that cycle with the younger generation and make owning a Windows tablet cool.  That is going to be a hard thing to do with the current generation of hardware and the prices that we are seeing today.

Karateka journal about making the game

karateka-paperback It has been a while since I read a book that I connected with on a personal level.  I read Jordan Mechner’s journal from when he was a teenager at Yale and started working on Karateka (amongst other things).  Kindle has an ebook version The Making Karateka.

This was an amazing read for me. Not because of the writing, but because of the subject. I was a middle school kid at the time Karateka came and I played the game on my Commodore 64, and was instantly mesmerized by the game and its effect it had on people. The story was good, but it was the first game that actually had a cinematic feel for the play. You felt like you were part of a movie. Now this was a kid version of me, but I was in awe.   My friends and I would play for hours and talk about how the animation was created.

I started writing games as a result of playing this one. I never achieved his level of success, but did have quite a few published while I was in high school. I even went on to work at a game company and made a few PC and console games in the mid 90’s.

Is this a book?

This is a collection of his personal journal during the time he built Karateka. It is raw and a little scattered. I went through all those same ups and downs as a kid (sort of still do as an adult!). It was refreshing to me to see something that I took to be an act of utter perfection was actually a labor of love for someone who struggled with it’s creation.

It was also a little scary to read wondering if he was going to flunk out of Yale.  I knew a lot of geeks when I was in college who ditched a lot of classes to work on projects, but few of them ever actually finished what they were working on.  So it is sort of amazing that Jordan was able to complete what he started, I think it was as much do to his parents encouragement as his own tenacity.

Fun geek read

Refreshing read to see that others in the same field had a similar start and rough road.  It is too easy to look back at your finished products and think it was obvious that is what was going to happen from the start.  Every project I have ever worked on goes through a similar path of finding the right deliverable.  You never start with a clean idea from the beginning and proceed to the end.  This was a fun geeky read.  Would have enjoyed hearing some of his coding travails as well, but this was very satisfying for a geek like me.

If you also know Jordan’s name he was the creator of Price of Persia and has published a journal about the creation of Prince of Persia.

Other Posts about the game

Found this great post about the game itself from another gamer.

Love Is a Backwards Kick: The Romance of Karateka

Had totally forgotten about that backward kick.

The game in the Karateka Classic Game in original 8 bit glory is available on iOS and Android.  I played through the Android version today, brought back a lot of memories.  Took me WEEKS to complete when I was a kid.  Having the rewind in the Android version saved a lot of time.

Inside Windows Phone # 34 – Talking CRUD with Jason Short

The interview I did for Channel 9 Inside Windows Phone is now up!

Channel 9 MSDN Link

Embedded Video

My thanks to Larry for having me on the show to talk about CRUD. People seem to think that with mobile apps the basic concepts of CRUD have gone away, but that is not true! You still need to think through the basic data operations the same as almost any other application.

Here is the post for the original XAPFest talk.

XAPFest talk Managing Data on Windows Phone 7

XAPFest talk Managing Data on Windows Phone 7

I did an after hours XAPFest talk a while back on Managing Data on Windows Phone 7 that is now published on the Microsoft Research site!  I am actually sort of proud that this session was the #2 most attended talk at XAPFest!

Microsoft Research – Managing Data on Windows Phone 7

I did a follow up blog post entitled Minimal virtualized data list for WP7 showing how to implement the code I spoke about in the video.  The source for that is available on Bitbucket.

Minimal Virtualized Data List for WP7

I recently gave a talk about data management on Windows Phone 7 for XapFest and I put in a slide about virtualizing your data for data bound objects.  I didn’t really think it was that big of a topic when I was putting together the talk, but it generated a lot of interest from attendees.

I am going to demonstrate the minimal virtualized data collection object you can easily create for data binding with a Listbox.

For this example I am using a simple class named FeedItemDataModel.  This represents a class that holds a single item from an RSS Feed.  In this simple implementation the values are simple and set in the constructor.

The sample application shows a UI with a collection of this object databound to the UI and lets you jump to a specific index in the list.  The red text you see is a memory watcher class that shows memory usage within your app.

Silverlight handles the UI part

To be clear, Silverlight handles the xaml part of this for you.  If you have a list with one million objects only the number that fit on screen are built up for the xaml display (from your DataTemplate most likely).  The runtime is smart enough to realize that the listitem is offscreen and recycle it for you.  This is a huge performance boost, but what about the data behind that databound collection?  If you bind one million objects they are all loaded into that collection by default!  If you want to only load those that are on screen you have to handle that yourself.  But it really is not that hard to do for most data objects.

Three “must have” parts

You don’t need to implement a lot of things to make data binding work against a custom object, but you must implement the following three things.  The below code snippet excludes a bunch of stuff you have to implement due to the interface, but you can just throw a not implemented exception.  You don’t need them to be completely implemented for this to work.

IndexOf – So the data binding can lookup a specific object and return it as the selected item.

Count – How many total items are in the collection. Listboxes need this to show the correct size scroll bar.

this[] – Go get the item, this could be from disk or from a cache.

public class MinVirtualizedList : IList
// Total items to show in the list
public const int TotalItems = 1000000;

/// <summary>
/// Count returns the total items in the list.
/// Important for the scrollbar to have a scale that matches the data
/// </summary>
public int Count
    get { return TotalItems; }

/// <summary>
/// Find the index of an object in the data list.
/// Important to allow quick seek access to the data position
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public int IndexOf(object value)
    if (value == null)
        return -1;

    FeedItemDataModel item = (FeedItemDataModel)value;
    return item.FeedItemId;

/// <summary>
/// Indexer for the list - this is where Silverlight will call back for each item that is
/// needed to fill the virtualized UI elements
/// </summary>
/// <param name="index">The index of the item to get</param>
/// <returns>The item</returns>
public object this[int index]
        // If using SterlingDB you would simple have to Load<FeedItemDataModel>(index)
        FeedItemDataModel loadedItem = null;
        loadedItem = new FeedItemDataModel { FeedItemId = index, FeedTitle = "Title " };
        return loadedItem;
        throw new NotImplementedException();
}  // See code on bitbucket for complete implementation with stubbed out methods

Load on Demand

You may be able to get away with always loading on demand if your objects are small.  I may update this sample later to include on demand loading using SterlingDB.  It would be really easy to implement, and I think there is value in having such a sample in the community.

Don’t be greedy

Only load the items you need.  If the user rarely scrolls down, don’t load anything beyond what a single screen can show (maybe a couple extra for the first part of the scroll).

Most apps may need a hybrid approach to this.  Either build a façade around your object and only load the parts that are needed for the UI, or load the smallest subset you expect the user to realistically consume.

Doesn’t IObservableCollection handle this?

I think this is a common misconception. ObservableCollections are for handling the change notifications to the UI. You only have to databind them one time, and when the collection is changed the UI gets updated. You could probably use the same technique here, but you would have to derive your own custom class.

Sample Code on BitBucket

I put the complete sample up on BitBucket, click the link to go direct to the source.

VirtualizedDataWP7 BitBucket Page

Cache in the collection

Another optimization would be to cache the objects in the collection.  This would be pretty easy to implement an MRU (most recently used) cache.  Sounds like another future blog post.

Create a file from a resource on WP7

I got an email from someone today asking about how to take a resource from their XAP (which is read only), and put it in a location where they can update the file.

Initial Data Load

I highly recommend this approach for getting an initial data load for your application.  Give the application a base of files to work with rather than requiring an initial round trip to a server for those files.  It is fine to need to update them almost immediately.  Think about the scenario where the user has no network access (a first run of the app this is really vital).  Does the user get an error that no data is available, or do they get a nice default experience?  Even if you just put in data that says “no data here yet”, that is better than a blank screen to the user.

Create File From Resource

I put this in a utilities class as a static method since it doesn’t really need any state.  One thing to ensure you do is put a using() block around the objects that are disposable.  This ensures they are cleaned up and released as quickly as possible.  I think this is a common reason why people think they need to GC.Collect, they are not cleaning up memory.

public class FileUtilities
/// <summary>
/// Given a resource name, create a file in the isolated storage.
/// Resources are read only, but copying them to the isolated store means you can edit them.
/// Useful for including a starter file in your XAP, and then copying it out to storage
/// for editing it at runtime.
/// </summary>
/// <param name="resourceName">The name of the resource</param>
/// <param name="fileName">Optional param for the name of the file, 
///       by default uses the same name as the resource</param>
public static void CreateFileFromResource(string resourceName, string fileName = null)
    // Find the resource and get the stream
    // Note the using() block to ensure this gets cleaned up when we are done
    using (var resourceStream = Application.GetResourceStream(
                                  new Uri(resourceName, UriKind.Relative)).Stream)
        // Get the location where we can write files
        using (var userStorage = IsolatedStorageFile.GetUserStoreForApplication())
            // Use the filename (if given) or the resource name
            using (var newFile = userStorage.CreateFile(fileName ?? resourceName))
                byte[] byteBuffer = new byte[4096];
                int bytesRead = -1;
                while ((bytesRead = resourceStream.Read(
                                     byteBuffer, 0, byteBuffer.Length)) > 0)
                    newFile.Write(byteBuffer, 0, bytesRead);

Please forgive the formatting above, trying to make it fit on a smaller size screen.

Using a custom attribute to determine type at runtime

On a Windows Phone 7 project I am currently building I had a need to build a factory that instantiates different concrete classes depending upon an object at runtime.   I have a number of information feeds, that all have different classes built to actually go get their data.  One for RSS Feeds, one for Twitter, etc.  Each Feed has a property for the FeedType, this is the information needed to determine what class to instantiate at runtime.

I have written this pattern many times, but I ran across an interesting post on StackOverflow where Steven gave a different approach to solving this without the classic giant switch statement in the Create method.   I thought it was neat enough to use in my application and share here.

There are a couple of steps you have to take, but none of them are difficult.

  • Decorate your objects with a custom attribute
  • Build the object types using reflection
  • Implement your factory method

Custom Attribute

The attribute I added is called FeedTypeAttribute, I then add it to the concrete feed processor classes.

class FeedTypeAttribute : Attribute
private int _feedType;

public FeedTypeAttribute(int feedType)
_feedType = feedType;

public int FeedTypeId
return _feedType;

Adding the attribute to a class looks like the following.

public class StaticFeedProcessor : IFeedProcessor
public StaticFeedProcessor()


public void ProcessFeedModel(FeedModel feedModel)
throw new NotImplementedException();

Note that this class would be a FeedType of 1 in my data, but how do you determine what class that is during runtime?  The answer is reflection (and yes, this does work on Windows Phone 7).


Factory Method Using Custom Attributes

public class FeedProcessorFactory : IFeedProcessorFactory
private static Dictionary<int, Type> processorList = new Dictionary<int, Type>();

static FeedProcessorFactory()
// Get the types in this assembly that implement our custom attribute
var targetTypes = from type in Assembly.GetExecutingAssembly().GetTypes()
where type.CanBeTreatedAsType(typeof(IFeedProcessor))
where !type.IsAbstract && !type.IsInterface
let customAttributes = type.GetCustomAttributes( typeof(FeedTypeAttribute), false)
let attribute = customAttributes[0] as FeedTypeAttribute
select new { type, attribute.FeedTypeId };

processorList = targetTypes.ToDictionary(p => p.FeedTypeId, p => p.type);

public IFeedProcessor CreateProcessorByFeedType(int feedId)
Type feedType = processorList[feedId];

return Activator.CreateInstance(feedType) as IFeedProcessor;

The key here is the type.GetCustomAttributes() call.  The linq expression gets all the type of the current assembly where the type can be assigned from the IFeedProcessor class.  We have to ensure the class is not abstract or an interface, and then get the custom attributes. 

The let clause in the linq expression can be thought of like a local temporary variable.  Assigning the attributes to it, and then processing them in the final select.

Consuming the Factory

Consuming the factory is then as simple as instantiating a factory object and calling the CreateProcessorByFeedType function.  A fully allocated processor is returned ready to handle the feed.

// This is in my container object
private static IFeedProcessorFactory _feedProcessorFactory = new FeedProcessorFactory();

// This is in the function to process the feeds
IFeedProcessor processor = _feedProcessorFactory.CreateProcessorByFeedType(feed.FeedType);

Less Coupling is Good

This code allows for the addition of new processor classes just by building the class and adding the custom attribute.  Of course you should check if the feedtype is not supported before trying to use the object (I omitted some code used for safety checking).
If a newer class is created in the future to replace a current one I only have to change the custom attribute to handle it.  No switch statements, or remembering to update a config somewhere.

Is this .Net Type Assignable from another Type?

I have run into this a few times and always have to go to the MSDN to find the answer.  I have a situation where I needed to determine if a given type can be treated as a base type in an object factory.  I wanted to be able to create my concrete classes without having to do a switch statement for each type.

First I had to determine if the types were assignable to each other, then find the type to implement.  I will cover that in another article.  In this one I just want to cover the assignment test.

Can this type be assigned?

There is a function IsAssignableFrom that you can call on a System.Type.

if( ParentType is ChildType )


It actually has to be written the other way around.

if( ChildType.IsAssignableFrom(ParentType) )


Quick Extension Method

So instead of having to do that all over my code, I wrote an extension method to allow me to do it following a different ordering.  I actually got this basic idea from one of the comments on the MSDN page.

if( parentType.CanBeTreatedAsType(childType) )


As you can see the extension method lets you write the syntax in a more natural manner.  Your preference may differ, but this makes more sense to me.

Example Code

public static class DataExtensionMethods
        public static bool CanBeTreatedAsType(this Type CurrentType, Type TypeToCompareWith)
            if (CurrentType == null || TypeToCompareWith == null)
                return false;

            return TypeToCompareWith.IsAssignableFrom(CurrentType);

void Main()
    System.Type parentType = typeof(ParentClass);
    System.Type childType = typeof(ChildClass);
    bool ChildToParent = childType.CanBeTreatedAsType(parentType);
    Console.WriteLine("Child can be treated as parent: " + ChildToParent );
    bool ParentAsChild = parentType.CanBeTreatedAsType(childType);
    Console.WriteLine("Parent can be treated as child: " + ParentAsChild );

public class ParentClass
    public ParentClass()

public class ChildClass : ParentClass
    public ChildClass() : base()