future of vb and c# lucian wischik vb language pm microsoft

52
Future of VB and C# Lucian Wischik VB Language PM Microsoft

Upload: jeffry-oliver

Post on 03-Jan-2016

220 views

Category:

Documents


1 download

TRANSCRIPT

Future of VB and C#

Lucian Wischik

VB Language PM

Microsoft

This is Vegas

WIN BIG MONEY !!!

Each speaker-eval earns $5 to Doctors Without Borders.Drop off at registration desk.

History

Managed Code

Generics

LINQ

Co-evolution

C#1, VB7

C#2, VB8

C#4, VB10

C#3, VB9

History

Async

Managed Code

Generics

LINQ

Co-evolution

C#1, VB7

C#2, VB8

C#4, VB10

C# vNext, VB11

C#3, VB9

History

Async

Managed Code

Generics

LINQ

Co-evolution

C#1, VB7

C#2, VB8

C#4, VB10

C# vNext, VB11

C#3, VB9

??? “Roslyn”

History

Async, Win8, CallerInfoVB: VBCore, Global, Iterators

Managed Code

Generics, EnC, My, partial,nullables, XML-comments

LINQ, lambdas, XML literals,type inference, extensions

Co-evolution, NOPIA,Dynamic/DLR, covariance

C#1, VB7

C#2, VB8

C#4, VB10

C# vNext, VB11

C#3, VB9

??? “Roslyn”

???

History

Async, Win8, CallerInfo,VB: VBCore, Global, Iterators

Managed Code

Generics, EnC, My, partial,nullables, XML-comments

LINQ, lambdas, XML literals,type inference, extensions

Co-evolution, NOPIA,Dynamic/DLR, covariance

C#1, VB7

C#2, VB8

C#4, VB10

C# vNext, VB11

C#3, VB9

??? “Roslyn”

???Async

CallerInfo

Roslyn

Async is a new, easier wayto write connected apps.

In the past…● “Connected” has generally meant either a

UI that freezes, or unmaintainable spaghetti code, or multithreading.

C# and VB future: Async…● Two new keywords: Await and Async in

VB and C#● A new Task-based design pattern for APIs,

the "T.A.P." (Task Asynchronous Pattern)● A new set of .NET Framework APIs

Async

CallerInfo

Roslyn

Async is a new, easier wayto write connected apps.

In the past…● “Connected” has generally meant either a

UI that freezes, or unmaintainable spaghetti code, or multithreading.

C# and VB future: Async…● Two new keywords: Await and Async in

VB and C#● A new Task-based design pattern for APIs,

the "T.A.P." (Task Asynchronous Pattern)● A new set of .NET Framework APIs

Async

CallerInfo

Roslyn

Fundamentals

Demo

How it works

Big picture

Async: Fundamentals

UI thread STOP

webClient.UploadString(uri);print("done");

So should you upload on a background thread? ...

“A waiter’s job is to wait on a table until the patrons have finished their meal.If you want to serve two tables concurrently, you must hire two waiters.”

The following is from the Android dev blog.Can you spot the flaw?

1. “A good practice in creating responsive applications is to make sure your main UI thread does the minimum amount of work.”

2. “Any potentially long task that may hang your application should be handled in a different thread.”

3. “Typical examples of such tasks are network operations, which involve unpredictable delays.”

How best to explain the sequence of events in a restaurant with several tables?

From the perspective of the patrons?

UI thread

or of the waiter?

Demo: async

Demo: async

This is the IL that’s emitted whenyou using async/await

Async: How it works

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

UIthread IOCP

thread

Async: How it works

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

[1/12] A button-click arrives on the UI queue

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

downTask

[2/12] Invoke some functions; get back “downTask” from the API

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

downTask

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

UIthread IOCP

thread

Click

downTask » sc.Post{Κ1}

[3/12] “await downTask” assigns a continuation and returns diggTask

Κ1:

diggTask

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

diggTask

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

downTask » sc.Post{Κ1}

[4/12] “await diggTask” assigns a continuation and returns

Κ1:

Κ2:

diggTask » sc.Post{Κ2}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

rss

[5/12] Network packet arrives with data

downTask » sc.Post{Κ1}

Κ1:

Κ2:

diggTask » sc.Post{Κ2}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

rsssc.Post{Κ1(rss)}

[6/12] Invoke downTask’s continuation with that data

downTask » sc.Post{Κ1}

Κ1:

Κ2:

diggTask » sc.Post{Κ2}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

diggTask » sc.Post{Κ2}

rss

K1(rss)

[7/12] Continuation is a “Post”, i.e. addition to the UI queue

Κ1:

Κ2:

sc.Post{Κ1(rss)}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

rss

K1(rss)

[8/12] UI thread executes K1, giving a result to the “await”

Κ1:

Κ2:

sc.Post{Κ1(rss)}

diggTask » sc.Post{Κ2}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

rss

K1(rss)

[9/12] “Return story” will signal completion of task

Κ1:

Κ2:

sc.Post{Κ1(rss)}

diggTask » sc.Post{Κ2}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

rss

K1(rss)

sc.Post(Κ2(story))

[10/12] Invoke diggTask’s continuation with data (by posting to UI queue)

K2(story)

Κ1:

Κ2:

sc.Post{Κ1(rss)}

diggTask » sc.Post{Κ2}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

UIthread IOCP

thread

Click

rss

K1(rss)

sc.Post(Κ2(story))

K2(story)

[11/12] Return from handling the K1 continuation

Κ1:

Κ2:

sc.Post{Κ1(rss)}

async void button1_Click()

{ var diggTask = GetDiggAsync();

var digg = await diggTask;

textBox1.Text = digg;

}

async Task<string> GetDiggAsync()

{ var web = new WebClient();

var downTask = web.DownTaskAsync("http://digg.com");

var rss = await downTask;

var digg = XElement.Parse(rss).<story>.<description>;

return digg;

}

rss

K2(story)

Click

K1(rss)

UIthread IOCP

thread

sc.Post(Κ2(story))

Κ1:

Κ2:

[12/12] UI thread executes K2, giving a result to the “await”

sc.Post{Κ1(rss)}

SINGLE-THREADED ASYNCHRONY AND CONCURRENCYis when we run asynchronous and concurrent tasks with NO additional threads (beyond those that the operating system already provides). No worries about mutexes &c. If you want extra threads, create them explicitly through Task.Run.

2008: Silverlight2:all its lengthy APIs are async

2010: [Feb] Windows Phone 7:all its lengthy APIs are async

2004: Asynchronous javascript (AJAX) hits big-time

2011: [August] a heckof a lot more async APIs…

Async:big picture

2010: [April] F# asyncships in VS2010

2010: [Oct] C#/VB Async CTPreleased at PDC

2011: [Oct] Async CTP v3,“as is” license

???: C#/VB asyncwill ship in VS.vNext

2008: Silverlight2:all its lengthy APIs are async

2010: [Feb] Windows Phone 7:all its lengthy APIs are async

2004: Asynchronous javascript (AJAX) hits big-time

2011: [August] a heckof a lot more async APIs…

Async:big picture

2010: [April] F# asyncships in VS2010

2010: [Oct] C#/VB Async CTPreleased at PDC

2011: [Oct] Async CTP v3,“as is” license

???: C#/VB asyncwill ship in VS.vNext

2008: Silverlight2:all its lengthy APIs are async

2010: [Feb] Windows Phone 7:all its lengthy APIs are async

2004: Asynchronous javascript (AJAX) hits big-time

2011: [August] a heckof a lot more async APIs…

F# is a trail-blazerfor language innovation

Async:big picture

2010: [April] F# asyncships in VS2010

2010: [Oct] C#/VB Async CTPreleased at PDC

2011: [Oct] Async CTP v3,“as is” license

???: C#/VB asyncwill ship in VS.vNext

2008: Silverlight2:all its lengthy APIs are async

2010: [Feb] Windows Phone 7:all its lengthy APIs are async

2004: Asynchronous javascript (AJAX) hits big-time

2011: [August] a heckof a lot more async APIs…

What to do while waiting for vNext? …

Async:big picture

Task

CPU Network I/O Composite

TASK UNIFIES ALL THESE AREAS; ASYNC TIES THEM TOGETHERUse Async Functions to compose other tasks, for the “orchestration” of your app

async Task DoWorkAsync() { try { string[] vidUrls = await ScrapeYoutubeAsync(url); // Network-bound Task<Video> t1 = DownloadVideoAsync(vidUrls(0)); // Start 2 downloads Task<Video> t2 = DownloadVideoAsync(vidUrls(1)); Video[] vids = await TaskEx.WhenAll(t1, t2); // Wait for both Video v = await MashupVideosAsync(vids(0), vids(1)); // CPU-bound await v.SaveAsync(textbox1.Text); // IO-bound } catch (WebException ex) { ReportError(ex); }}

Async

CallerInfo

Roslyn

CallerInfowill help with logging and in boilerplatecode like INotifyPropertyChanged.

void Log([CallerLineNumber] int line = 0, [CallerFilePath] string f = null, [CallerMemberName] string m = null){ Console.WriteLine(“{0}:{1} - {2}”, f, line, m);}

Async

CallerInfo

Roslyn

Demo: CallerInfo

Async

CallerInfo

Roslyn

Roslynis about opening up the internals of the compilerto let everyone use the VB/C# languagesin powerful ways.

Async

CallerInfo

Roslyn

Roslynis about opening up the internals of the compilerto let everyone use the VB/C# languagesin powerful ways.

Async

CallerInfo

Roslyn

IL emitBinderSymbols

MetaimpParser

IL emitBinderSymbols

MetaimpParser

Syntax tree API

SymbolAPI

Bind/flowAPI

EmitAPI

IL emitBinderSymbols

MetaimpParser

Syntax tree API

SymbolAPI

Bind/flowAPI

EmitAPI

ColorizerFormatterOutlining

NavigateToObjBrowser

GoToDefExtractMeth

QuickInfoRename

FindAllRefsIntellisense EnC

IL emitBinderSymbols

MetaimpParser

Syntax tree API

SymbolAPI

Bind/flowAPI

EmitAPI

ColorizerFormatterOutlining

NavigateToObjBrowser

GoToDefExtractMeth

QuickInfoRename

FindAllRefsIntellisense EnC

Interactive “REPL” window

Script files (think .vbs) -- .csx .vbx

Use C#/VB as scripting languages for your app

Demo: Roslyn

Async

CallerInfo

Roslyn

Async• Download the Async CTP

http://msdn.com/async• Start making Task-returning APIs today

CallerInfo• Wait patiently…

Roslyn• Download the Roslyn CTP

http://msdn.com/roslyn• Give us feedback

Async

CallerInfo

Roslyn

Module Module1 Sub Main() Dim robots = {"Number5", "Asimo", "Cylon"}

Dim xml = <html> <head> <title>Robot Status</title> </head> <body> <ul> <%= Iterator Function() For Each r In robots Yield <li>Robot <%= r %> reporting for duty</li> Next End Function() %> </ul> </body> </html>

Console.WriteLine(xml) End SubEnd Module

A parting wordfrom VB:

ITERATORLAMBDAS!