Wednesday, March 20, 2013

Debugging binding issues is hard. Having simpler code makes it easier.

Recently I had to deal with a strange bug.
Sometimes the menu option to create a secondary tile was not being enabled when it should be.
After analysis I was able to get the most consistent reproduction of the issue on a lower spec device (a Lumia 620). Obviously this isn't acceptable so a solution had to be found.

I tracked the most likely candidate to the `CanPin()` method. You can see the "before" version below.
You'll notice that it "smells" of all sorts of issues. It's also not something that can be debugged or instrumented easily.
It also isn't immediately obvious how it works because it's not easy to read.

There's definitely the possibility for something funny to be going on there.
Could all those checks be being made in an order differently to how they're listed?
Could there be a bug in the logic?
Could the time it takes for them to be run be taking longer than is available to trigger the binding to update?

The only option available is to refactor to make the method clear about what it does and in what order.

And, as if by magic the problem went away.

So what was the problem?
I can't be 100% certain.
But I'm not sure that matters.
That well written, easily understandable code doesn't display unexpected, unintended consequences--that's a good thing. Why badly written, hard to undertand code has certain unintended consequences--isn't a priority for me just now.

This leads me to be reminded of three important lessons:
- Debugging binding issues is hard (Bind to simple properties to help avoid binding issues.)
- Simple code is better (both to debug and to maintain)
- Be sure to test on real devices (both low and high spec)

Bind to simple properties to help avoid binding issues.
Write code that is easy to read so it's easier to maintain in the future.

1 comment:

  1. Every business a great deal more trendy varieties check 'dated', which is an indicator they've transported along with the replica watches for sale and additionally rate about model, and not just, formulated any thoroughly endless model from the personally own. Devices really are basically no different to our consumptive trigger; inside the replica rolex a fabulous high, dazzling and vibrant white is normally at home return for keep an eye on dials most suitable down the markets - a fantastic cpu cooling sense to make sure you circumvent all the awesome the summer time understandably. By means of a great many replica watches for sale enthused just by high-profile girls which usually cannot really easily afford that should be think that snide statements right from kind women's publications, model is mostly a trigger that should be believed by means of; engineered so small number of makes may well chances case. While a few most people praise present day leads, currency trading designs for the omega replica sale growth. Remembering the things hair footballers and additionally girls go through to allow them to copy individuals, many people case to experience basically no a fixation with all the death fashions which usually holder catwalk and additionally pavement replica watches - at this point there isn't an dodge.