what does it take to make mine for facebook: learn and apply to your next windows store app

36
MINE for Facebook - a case study Kevin Dockx, @KevinDockx, RealDolmen

Upload: microsoft-developer-network-msdn-belgium-and-luxembourg

Post on 13-Jan-2015

522 views

Category:

Technology


1 download

DESCRIPTION

Presented by Kevin Dockx at the Windows App Day in Antwerp, Belgium on November 23, 2012.

TRANSCRIPT

Page 1: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

MINE for Facebook - a case studyKevin Dockx, @KevinDockx, RealDolmen

Page 2: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

What are we talking about?

A little story…

Five essentials, and how to achieve them

Agenda

Page 3: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app
Page 4: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

A LITTLE STORY…

Page 5: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

THE FACEBOOK API

… voted “Worst API of 2011” in developer survey

“buggy”

“unreliable”

“lack of documentation”

“slow response times”

“neverending API changes”

Page 6: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Five essentials, and how to achieve themFOCUS.LOOKS.RELIABILITY.PERFORMANCE.STATISTICS & LOGS.

Page 7: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

FOCUS

Page 8: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

LOOKS

Page 9: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Start hub

Page 10: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Story feed

Page 11: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Single story

Page 12: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

RELIABILITY

Page 13: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Architecture

MINE.FacebookSDKBroker

MINE.Framework

MINE.Framework.WinRTComponent

MINE.FacebookClient

MINE.FacebookClient.BackgroundTask

MINE.FacebookClient.Common

Page 14: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

What’s used inside those components?MVVM => MVVM Light

Data format & parsing => JSON .NET

Connecting to Facebook => Facebook C# SDK

Page 15: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Architecture & components

MINE.FacebookSDKBroker

MINE.Framework

MINE.Framework.WinRTComponent

MINE.FacebookClient

MINE.FacebookClient.BackgroundTask

MINE.FacebookClient.Common

MVVM Light, JSON .NET, FB SDK

JSON .NET, FB SDK

JSON .NET

Page 16: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Advantages of this architectureProven components, backed by community

Reuse in & outside of current project, WinRT component or otherwise

Takes a bit of time initially, but saves tremendous amounts of time after a while

Page 17: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

One more tip: assume failure

Failunless

(condition A)

or(condition

B)

if (condition Z) Fail

else if (condition A)

do Aelse …

Page 18: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

PERFORMANCE

Page 19: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Cancellation of tasksProblem: tasks run when I don’t need them anymore.

Solution: support Cancellation- Built-in- What about your own methods?

– Accept a Cancellation Token in your method signature– Check for cancellation in that method– Handle OperationCancelledException

Page 20: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Produce, Consume, Consume, ProduceProblem: different parts of code need access to objects from different threads

Solution: Producer/Consumer pattern- BlockingCollection<T>- TryAdd to add to collection- TryTake to take from collection- CompleteAdding to notify end of adding

Page 21: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Performance – the usual suspects- Offload long-running tasks to the background- Cancel Tasks when they’re no longer needed- Use async/await, Task.WhenAny, Task.WhenAll- Use an extended splash screen- Prefetch when possible- Show progress, determinate or indeterminate

- Profile your app using the performance profiler

Page 22: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Performance - the illusion of performance

Perception beats reality. Always.

Page 23: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Performance case: the story feed- “Show me the next 20 items”

- Easy, right? Fetch items, translate them, return them, add to bound collection

- What was done?- Prefetch with producer/consumer- On scroll, items often are in backing collection => immediate return- Consumer asks for items one by one instead of 20 at the same time- Results in perception of faster performance

Page 24: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Performance: reduce memory consumption- Well, hello captain obvious. Obvious? Yes, but for an additional reason

- The less memory your app uses, the more likely it is to stay in memory instead of being terminated, ensuring a faster restart after being suspended

Page 25: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

XAML PerformanceDo not load resources that aren’t necessary• Resource Dictionaries are fully parsed, even though your page might

only use one resource of it• Your start page shouldn’t use application-wide dictionaries• If you use a resource throughout your app, put it in Application (through

a resource dictionary)• If you don’t, only reference that dictionary on the pages it is used, or

even in the page-specific resource dictionary

Page 26: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

XAML PerformanceOptimize element count• Don’t write this:

<Grid> <Rectangle Fill="Black"/>

</Grid>

• But write this:

<Grid Background=“Black” />

Page 27: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

XAML PerformanceReuse brushesDon’t write this:

<TextBox> <TextBox.Foreground> <SolidColorBrush Color="#FF3F42CC"/>

</TextBox.Foreground> </TextBox> <Button Content="Submit"><Button.Foreground>

<SolidColorBrush Color="#FF3F42CC"/> </Button.Foreground> </Button>

Write this:<TextBox Foreground="{StaticResource TextColor}" />

<Button Content="Submit" Foreground="{StaticResource TextColor}" />

Page 28: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

XAML PerformanceMinimize redrawing to the same place on the screenDon’t write this

<Grid Background="Black"> <Grid.RowDefinitions>

<RowDefinition Height="*"/> <RowDefinition Height="*"/>

</Grid.RowDefinitions> <Rectangle Grid.Row="1" Fill="White" Opacity=".5"/> </Grid>

Page 29: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

XAML PerformanceBut write this:

<Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Rectangle Grid.Row="1" Fill="Black"/> <Rectangle Grid.Row="1" Fill="#FF7F7F7F"/></Grid>

There’s more: http://msdn.microsoft.com/en-us/library/windows/apps/hh994641.aspx

Page 30: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

STATISTICS & LOGS

Page 31: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Marked Up- User statistics

- Sessions, users, app installations, …

- Crashes, errors & diagnostics- Custom logging, exceptions, crashes, including full stacktraces

- Usage statistics- Time spent in the application, page views, custom events, …

- Commerce statistics

Page 32: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Marked Up – how?- Init

MarkedUp.AnalyticClient.Initialize(“key");

- Catch navigation

MarkedUp.AnalyticClient.RegisterNavigationFrame(rootFrame);

- Log excepMarkedUp.AnalyticClient.LogLastChanceException(e);tions

Page 33: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

SummaryFOCUS.

LOOKS.

RELIABILITY.

PERFORMANCE.

STATISTICS & LOGS.

Page 34: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app
Page 35: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

Build apps on Windows. Discover your new home.

http://msdn.be/apps

Page 36: What does it take to make Mine for Facebook: learn and apply to your next Windows Store app

THANK YOU