Your SlideShare is downloading. ×
0
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Ft10 de smet
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ft10 de smet

710

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
710
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1.
  • 2. LINQ, Take TwoRealizing the LINQ to Everything Dream<br />Bart J.F. De Smet<br />Software Development Engineer<br />Microsoft Corporation<br />
  • 3. What’s LINQ?A historical perspective<br />5 years ago<br />Little recent innovation<br />Where’s the cloud?<br />Censored<br />
  • 4. Essential LINQLanguage Integrated Monads<br />Why?<br />What?<br />How?<br />
  • 5. Could there be more?<br />Essential LINQThe monadic Bind operator<br />IEnumerable<T><br />IQueryable<T><br />new[]{ 42 }<br />IEnumerable<T> SelectMany<T, R>(this IEnumerable<T> source,Func<T, IEnumerable<R>> selector)<br />SelectMany<br />Also see www.codeplex.com/LINQSQO for “Project MinLINQ”<br />
  • 6. Essential LINQMaybe monad (for fun and no profit)<br />Null-propagating dot<br />string s = name?.ToUpper();<br />One single library function suffices<br />Syntactic sugar<br />name.SelectMany( _ => _.ToUpper(),<br /> s => s)<br />from _ in name<br />from s in _.ToUpper()<br />select s<br />Compiler<br />
  • 7. Essential LINQ<br />Bart J.F. De Smet<br />Software Development Engineer<br />Cloud Programmability Team<br />demo <br />
  • 8. Query Providers RevisitedWhy do we have IQueryable<T>?<br />Does it really have to be a runtime check?<br />Implements<br />IQueryable<T><br />varsrc = newQueryProvider<Product>();<br />varres = from p insrc<br />wherep.Price > 100m<br />groupp byp.Category;<br />foreach(var p in res)<br />Console.WriteLine(p);<br />Compiles fine<br />
  • 9. Query Providers RevisitedLeveraging the query pattern<br />varres = from p insrc<br /> wherep.Price > 100m<br />groupp byp.Category;<br />Syntactic sugar<br />varres = src<br />.Where(p => p.Price> 100m)<br />.GroupBy(p => p.Category);<br />No GroupBy“edge”<br />Can be instance methods<br />Select<br />Where<br />Source<T><br />Filtered<T><br />Projected<T><br />
  • 10. Query Providers RevisitedTaking it one step further<br />Recipe<br />Method overloads<br />Type state machine<br />Operator overloads<br />varres = fromtweet intwitter<br /> where tweet.<br /> == “Bart”<br />From<br />About<br />From<br />Location<br />From<br /> == “LINQ”<br /> where tweet.<br />About<br />About<br />About<br />Location<br /> select tweet;<br />Query “learns”<br />From operator overloading<br />“Has a” type<br />classTwitter<br />{<br />publicTwitterByFromWhere(Func<TweetAboutFromLoc, FilterFrom> filter);<br />// Other filter methods<br />}<br />classTwitterByFrom<br />{<br />publicTwitterByAboutFromWhere(Func<TweetAboutLoc, FilterAbout> filter);<br />// Other filter methods<br /> // Fields with current filters<br />}<br />Custom syntax trees<br />
  • 11. Query Providers Revisited<br />Bart J.F. De Smet<br />Software Development Engineer<br />Cloud Programmability Team<br />demo <br />
  • 12. Asynchronous Data Access<br />(𝑓 ◦ 𝑔)(𝑥) = 𝑓(𝑔(𝑥))<br /> <br />Way simpler with Rx<br />Rx is a library for composing asynchronous and event-basedprograms using observable collections.<br />Queries! LINQ!<br />Download at MSDN DevLabs<br /><ul><li>.NET 3.5 SP1 and 4.0, Silverlight 3 and 4
  • 13. JavaScript (RxJS)
  • 14. XNA 3.1 for XBOX and Zune
  • 15. Windows Phone 7</li></li></ul><li>Asynchronous Data AccessPush-based data retrieval<br />Application<br />Got next?<br />MoveNext<br />Interactive<br />Reactive<br />OnNext<br />Have next!<br />Environment<br />IObservable<T><br />IObserver<T><br />IEnumerable<T><br />IEnumerator<T><br />
  • 16. Asynchronous Data AccessEssential interfaces<br />interfaceIObservable<outT><br />{<br />IDisposableSubscribe(IObserver<T> observer);}<br />interfaceIObserver<in T><br />{<br />voidOnNext(T value);<br />voidOnError(Exception ex);<br />voidOnCompleted();<br />}<br />Both interfaces ship in the .NET 4 BCL<br />
  • 17. IQbservable<T><br />LINQ to WMI Events<br />How?<br />ToQbservable<br />Translatable<br />(Expression trees)<br />IQueryable<T><br />LINQ to SQL<br />ToQueryable<br />LINQ to *.*<br />AsObservable<br />Homo-iconic<br />AsEnumerable<br />AsQbservable<br />AsQueryable<br />ToObservable<br />IEnumerable<T><br />LINQ to Objects<br />IObservable<T><br />LINQ to Events<br />Fixed<br />(MSIL)<br />ToEnumerable<br />Pull(interactive)<br />Push<br />(reactive)<br />What?<br />Duality<br />Concurrency(IScheduler)<br />Where?<br />Message loops<br />Distributed<br />Worker pools<br />Threads<br />
  • 18. IObservable<T><br />Asynchronous Data AccessIQbservable<T><br />interfaceIQbservable<outT> : IObservable<T><br />{<br />ExpressionExpression { get; }<br />TypeElementType { get; }<br />IQbservableProvider Provider { get; }<br />}<br />interfaceIQbservableProvider<br />{<br />IQbservable<R> CreateQuery<R>(Expression expression);<br />}<br />We welcome semantic discussions.<br />Extended role for some operators<br />No Execute method<br />
  • 19. LINQ to WMI Events (WQL)<br />Bart J.F. De Smet<br />Software Development Engineer<br />Cloud Programmability Team<br />demo <br />
  • 20. Asynchronous Data AccessC# 5.0 and VB 11.0 “await”<br />One versus many?<br />IObservable<T> interface – many results<br />Task<T> concrete class – one result<br />Task<T> based language feature<br />Rx bridge by implementing the “await pattern”<br />IAsyncEnumerable<T><br />
  • 21. Asynchronous Bridge for C# and VB “await”<br />Bart J.F. De Smet<br />Software Development Engineer<br />Cloud Programmability Team<br />announcing<br />
  • 22. Where execution happensIScheduler interface<br />System.Concurrencyin System.CoreEx<br />Introduction of concurrency<br />interfaceIScheduler<br />{<br />DateTimeOffsetNow { get; }<br />IDisposable Schedule(Action action);<br />IDisposable Schedule(Actionaction, TimeSpandueTime);}<br />ToObservable<br />IObservable<T><br />IEnumerable<T><br />ToEnumerable<br />Synchronous<br />Asynchronous<br />
  • 23. Where execution happensIScheduler specifies “where”<br />Imported TextBoxTextChangedevent<br />var res = from word ininput.DistinctUntilChanged()<br /> .Throttle(TimeSpan.FromSeconds(0.5))<br />from words in lookup(word)<br />select words;<br />Asynchronous web service call<br />Indicates where things run<br />Use of scheduler to synchronize<br />res.Subscribe(words => {<br />lst.Items.Clear();<br />lst.Items.AddRange((fromwordinwords<br />selectword.Word).ToArray());});<br />res.ObserveOn(newControlScheduler(frm)).Subscribe(words => {<br />lst.Items.Clear();<br />lst.Items.AddRange((fromwordinwords<br />selectword.Word).ToArray());});<br />
  • 24. Where execution happensIScheduler parameterization<br />Baked in notion of “where”?<br />Entry-point for the schema<br />Custom schedulers could be very rich (e.g. server farm)<br />varctx = new NorthwindDataContext(); <br />var res = from product inctx.Products<br />whereproduct.Price > 100m<br />selectproduct.Name;<br />Decoupled “what” from “where”<br />foreach(varproduct inres.RemoteOn(newSqlScheduler(“server”)))<br /> // Process product<br />
  • 25. Where execution happensExpression tree remoting<br />Rx .NET<br />fromtickerinstocks<br />whereticker.Symbol == “MSFT”<br />selectticker.Quote<br />Observable data source<br />JSON serializer<br />Retargeting to AJAX<br />RxJS<br />stocks<br />.Where(function (t) { returnt.Symbol == “MSFT”; })<br />.Select(function (t) { returnt.Quote; })<br />
  • 26. Remoting of Query Operators<br />Bart J.F. De Smet<br />Software Development Engineer<br />Cloud Programmability Team<br />demo <br />
  • 27. LINQ to the unexpectedConstraint solving<br />Non-persistent<br />Model[<br />Decisions[Reals, SA, VZ],<br /> Goals[<br />Minimize[20 * SA + 15 * VZ]<br /> ],<br />Constraints[ <br /> C1 -> 0.3 * SA + 0.4 * VZ >= 2000,<br /> C2 -> 0.4 * SA + 0.2 * VZ >= 1500,<br /> C3 -> 0.2 * SA + 0.3 * VZ >= 500,<br /> C4 -> SA <= 9000,<br /> C5 -> VZ <= 6000,<br /> C6 -> SA >= 0,<br /> C7 -> VZ >= 0<br /> ]<br />]<br />fromminctx.CreateModel(new {<br />vz = default(double),<br /> sa = default(double)<br />})<br />where 0.3 * m.sa + 0.4 * m.vz >= 2000<br /> && 0.4 * m.sa + 0.2 * m.vz >= 1500<br /> && 0.2 * m.sa + 0.3 * m.vz >= 500<br />where 0 <= m.sa && m.sa <= 9000<br /> && 0 <= m.vz && m.vz <= 6000<br />orderby 20 * m.sa + 15 * m.vz<br />selectm<br />Cost / barrel<br />Refinement %<br />Max # barrels<br />Min # barrels<br />To compute call Solve<br />
  • 28. LINQ to the unexpectedJoining with reactive sources<br />Observabledata sources<br />fromcostSAinGetPriceMonitor("SA")<br />fromcostVZinGetPriceMonitor("VZ")<br />fromminctx.CreateModel(new { vz = default(double),<br />sa = default(double) })<br />where0.3 * m.sa + 0.4 * m.vz >= 2000<br /> && 0.4 * m.sa + 0.2 * m.vz >= 1500<br /> && 0.2 * m.sa + 0.3 * m.vz >= 500<br />where0 <= m.sa && m.sa <= 9000<br /> && 0 <= m.vz && m.vz <= 6000<br />orderbycostSA* m.sa + costVZ* m.vz<br />selectm<br />SelectMany<br />Subscribe here!<br />Parametersto decision<br />
  • 29. Theorem Solving using Z3<br />Bart J.F. De Smet<br />Software Development Engineer<br />Cloud Programmability Team<br />demo <br />
  • 30. What’s LINQ?A futuristic perspective<br />Next 5 years<br />Scheduler<br />Remoting<br />Solvers<br />Rx and Ix are here!<br />Toolkits<br />Async<br />Censored<br />
  • 31. © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />

×