Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trends in Programming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart

Similar presentations


Presentation on theme: "Trends in Programming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart"— Presentation transcript:

1 Trends in Programming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart bartde@microsoft.com

2 DEMO The Good Old Days?

3 Looking at the Past… Assembler Procedural Objects Managed Richer Runtimes Ease of Use Richer Runtimes Ease of Use More Control Too low-level More Control Too low-level

4 Languages, Frameworks, Tools

5 Hardware Trends x 10,000 x 100,000 x 1,000 What about SSD? What about NUMA? What about many-core?

6 Aim Higher or Lower? Higher Levels of Abstraction Richer Frameworks (e.g..NET) Language Innovation (e.g. C#) Improved Expressiveness (e.g. FP) Low-Level Plumbing Can we avoid the disconnect? Machine Architectures (e.g. ARM) Power Consumption (e.g. phone) Rich Capabilities (e.g. GPU)

7 Two Stories on Bridging the Gaps GPU Acceleration Asynchronous I/O Win32 APIs Common Language Runtime Task Parallel Library C# and VB vNext DirectX APIs Internet Explorer 9 Rendering HTML 5 Canvas User System Established Reality! Rocket Science? Time

8 Software Trends 8 Horse-power of many-core… …but how to program those? Concurrent Say what you want… …not how it has to be done? Declarative Schematized, static, dynamic… …so, what’s the sweet spot? Dynamic New level of expressiveness… …how about the essence? Functional But will it blend?

9 FUNCTIONAL PROGRAMMING Increasing the level of abstraction

10 A Different Approach Theory of Computation (Lambda Calculus, Alonzo Church) LISP Heritage Reality of Hardware (Memory, John Von Neumann) Fortran Heritage Basic SmallTalk Modula C C++ Java C# Scheme SASL Haskell ML Miranda CLU

11 Lambda Expressions are All Around Us var res = xs.Where(x => x % 2 == 0); C# Dim res = xs.Where(Function(x) x Mod 2 = 0) Visual Basic let res = xs |> Seq.filter (fun x -> x % 2 = 0); F# var res = xs.filter(function(x) { return x % 2 == 0; }); JavaScript auto res = find_if(xs.begin(), xs.end(), [] (int i) { return x % 2 == 0; }); C++0x

12 What’s the Buzz About? Why? What? How? John Hughes F# Clojure Scala LISP Haskell

13 Have We Forgotten About Math? x = x + 1

14 Defining Functions No notion of time

15 Aargh… Those Pesky Side-Effects let equal = sin(0.0) = sin(0.0) let sinzero = sin(0.0) in sinzero = sinzero Binds name to value Equality != assignment let equal = DateTime.Now = DateTime.Now let now = DateTime.Now in now = now Not a pure function… Immutability is the default

16 But We Like Side-Effects So Much… // C# syntax static void Main(string[] args) { Console.WriteLine(args.Length); } (* F# syntax *) let main (args : string array) = printf "%d\n" args.Length val main : string array -> unit In Haskell: IO unit I/O is a side-effect Philip Wadler Hmm… monads

17 Programming in a Functional Style FP First class functions Immutable data Referential transparency Algebraic data types Type inference Pattern matching Essence Niceties But what’s a function?

18 F# – A General-Purpose Functional Style Language Visual Studio.NETFunctional F#

19 DEMO Functional Programming Programming with Functions

20 An Exercise In Purity? $$$ $ Impure Pure Purify yourselves, sinners! Erik MeijerSimon Peyton-Jones Where does F# fit?

21 DYNAMIC PROGRAMMING The world isn’t always typed

22 Dynamic vs. Static Dynamic Languages Simple and succinctImplicitly typedMeta-programmingNo compilation Static Languages RobustPerformantIntelligent toolsBetter scaling REST JavaScript Ruby JSON Python

23 It’s a Dynamic World Trend on non-schematized data Remember WSDL, SOAP, XSD? How about REST, JSON? The next browser war JavaScript on the web Optimized scripting engines Towards metaprogramming? Ruby community Code as data

24 32-bit value Type tag 32-bit value Type tag 32-bit value Loop back to dispatcher Fetch next byte code Call generic add handler Check for overflow Store type tag of result Store value of result Load type tag of a Load type tag of i Select add operation Load value of a Load value of i Dynamic vs. Static var a = 0; for (var i = 0; i < n; i++) { a = a + i; } ADD instruction 10-100 X int a a i i

25 Dynamic VM Advances Interpretation Dynamic Typing Operation 10-100 X Interpreter Dynamic Typing Operation 3-10 X JIT Compiler Operation 2-3 X Adaptive JIT Compiler Inline Caching Type Specialization Hidden Classes Tracing Inline Caching Type Specialization Hidden Classes Tracing

26 Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder.NET Dynamic Programming Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPythonIronPythonIronRubyIronRubyC#C#VB.NETVB.NETOthers…Others…

27 DEMO Dynamic Code and Data

28 Compiler as a Service 28 Class Field public Foo private string X X Compiler Source code Source File Source code.NET Assembly Meta-programmingRead-Eval-Print Loop Language Object Model DSL Embedding

29 CONCURRENT PROGRAMMING Dealing with hardware reality

30 Taming the Concurrency Monster Can you keep the cores busy? Gordon Moore

31 …can be hard Concurrent programming with shared state…

32 Operating System Threads Parallel Extensions in.NET 4 Parallel LINQ Task Parallel Library Coordination Data Structures CPU …

33 Task- oriented Data- oriented Rich composition Coordination and scheduling TPL Task PLINQ CDS, etc. Continuations Task Parallel Library in.NET 4

34 Expressing Parallelism – A Library Approach int[,] Multiply(int[,] m1, int[,] m2) { int m, n, o; // Left as an exercise var res = new int[m, o]; Parallel.For(0, m, i => { for (int j = 0; j < o; j++) { res[i, j] = 0; for (int k = 0; k < n; k++) { res[i, j] += m1[i, k] * m2[k, j]; } }); return res; } int[,] Multiply(int[,] m1, int[,] m2) { int m, n, o; // Left as an exercise var res = new int[m, o]; for (int i = 0; i < m; i++) { for (int j = 0; j < o; j++) { res[i, j] = 0; for (int k = 0; k < n; k++) { res[i, j] += m1[i, k] * m2[k, j]; } return res; } Embarrassingly Parallel Lambda expressions to the rescue

35 Expressing Parallelism – A Library Approach var source = Enumerable.Range(1, 10000); var res = from x in source.AsParallel() where f(x) select g(x); res.ForAll(x => { Process(x); }); var source = Enumerable.Range(1, 10000); var res = from x in source where f(x) select g(x); foreach (var x in res) Process(x); Natural Data Parallelism Extension methods to the rescue

36 Asynchronous Programming – Low Hanging Fruit? Your Program Here Events triggered I/O completed Packet received Events Callbacks Reactive

37 Asynchronous Programming Simplified 37 Don’t block! UI programming, Windows Phone 7, Silverlight Latency ahead! Dealing with networks, services, cloud A blocking call! var data = DownloadData(…); ProcessData(data); Callback twists your code inside out var data = DownloadDataAsync(…, data => { ProcessData(data); }); var data = await DownloadDataAsync(…); ProcessData(data); No longer blocking! Visual Studio Async CTP

38 DEMO Using the TPL and the Async CTP

39 Potential Language Constructs Immutability Purity Isolation

40 DECLARATIVE PROGRAMMING Just say what you want

41 Domain Specific Languages DSLGPPL DSL External DSLInternal DSL

42 External DSLs SELECT Name, Address, City FROM Customers WHERE Country = "Belgium" rm -f /tmp/listing.tmp > /dev/null 2>&1 touch /tmp/listing.tmp ls -l [a-z]*.doc | sort > /tmp/listing.tmp lpr -Ppostscript_1 /tmp/listing.tmp rm -f /tmp/listing.tmp

43 Internal DSLs class Order < ActiveRecord::Base belongs_to :customer has_many :details end var query = db.Customers.Where(c => c.City == "London").OrderBy(c => c.CompanyName).Select(c => c.CompanyName); $(document).ready(function() { $("a").hover(function() { $(this).parents("p").addClass("highlight"); }, function() { $(this).parents("p").removeClass("highlight"); });

44 DEMO LINQ as an Internal DSL

45 Exciting Times 45 Horse-power of many-core… …but how to program those? Concurrent Say what you want… …not how it has to be done? Declarative Schematized, static, dynamic… …so, what’s the sweet spot? Dynamic New level of expressiveness… …how about the essence? Functional

46 Stay up to date with MSDN Belux Register for our newsletters and stay up to date: http://www.msdn-newsletters.be Technical updates Event announcements and registration Top downloads Follow our blog http://blogs.msdn.com/belux Join us on Facebook http://www.facebook.com/msdnbe http://www.facebook.com/msdnbelux LinkedIn: http://linkd.in/msdnbelux/ Twitter: @msdnbelux Download MSDN/TechNet Desktop Gadget http://bit.ly/msdntngadget

47 TechDays 2011 On-Demand Watch this session on-demand via Channel9 http://channel9.msdn.com/belux Download to your favorite MP3 or video player Get access to slides and recommended resources by the speakers

48 THANK YOU


Download ppt "Trends in Programming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart"

Similar presentations


Ads by Google