Perhaps interesting times are ahead

I have just been moved over to work within Windows Engineering here at Microsoft.  I will be working on a team that is focusing on bringing developers back to Windows.  Some of that will be UWP focused, some will be “legacy” apps (meaning WinForms, WPF, pretty much everything not a store app today).

So I am getting back to building a lot more apps that are not huge complex Azure systems!  Hopefully that will mean more blog posts and source code I can share publicly.

I attended Xamarin Evolve a few weeks ago and will post a summary from my perspective (it was really good). 

I posted a UWP Memory Helper utility class on Github last week.  It is a really simple class to help you track memory usage while running your apps.  I used to use this for my Windows Phone apps, but the utility didn’t work with UWP.

I also updated my Virtualized List to support Windows 10 UWP.  It is a simple example showing how to build a virtualized list that you can databind in XAML and still get fast performance for scrolling.

So maybe interesting times are ahead where I will get to publish more blogs and contribute more open source.  We shall see.

A whole year without a single post

Wow, it has been a year since my last post.  I didn’t want to blog for 2015, and I didn’t.  I am now trying to decide if I should go back to it at all.  Social media, twitter and other short form media dominated my 2015.  I feel much more engaged with those types of media because people respond and interact with you.  It seems like the day of the blog are dying.  Maybe for long how to articles, deep dives, etc.  But I think for engagement the blog is now gone.  Comment spam was a big part of it, but people are now more mobile and read smaller articles on the go.

So do I kill off my blog and domain?  I can’t decide.  I do some blogging for more complex topics through my job, but I use MSDN blogs for that.  I get far better reach and linking because it is MSDN!


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.