Trends in Programming Languages Bart J F De
Trends in Programming Languages Bart J. F. De Smet blogs. bartdesmet. net/bartde@microsoft. com
DEMO The Good Old Days?
Looking at the Past… More Control Too low-level Objects Managed Procedural Assembler Richer Runtimes Ease of Use
Hardware Trends What about SSD? x 100, 000 What about NUMA? x 10, 000 What about many-core? x 1, 000
Aim Higher or Lower? Higher Levels of Abstraction • Richer Frameworks (e. g. . NET) • Language Innovation (e. g. C#) • Improved Expressiveness (e. g. FP) Can we avoid the disconnect? Low-Level Plumbing • Machine Architectures (e. g. ARM) • Power Consumption (e. g. phone) • Rich Capabilities (e. g. GPU)
Two Stories on Bridging the Gaps HTML 5 User System Rocket Science? Canvas C# and VB v. Next Task Parallel Library Internet Explorer 9 Rendering Common Language Runtime Direct. X APIs Win 32 APIs Established Reality! Time GPU Acceleration Asynchronous I/O
Software Trends Concurrent • Horse-power of many-core… • …but how to program those? Declarative • Say what you want… • …not how it has to be done? Dynamic ? d n e l • Schematized, static, dynamic… b t • …so, what’s the sweet spot? i li l w • New level of expressiveness… t Functionalu • …how about the essence? B 8
Increasing the level of abstraction FUNCTIONAL PROGRAMMING
A Different Approach Miranda CLU LISP Heritage Scheme ML Theory of Computation (Lambda Calculus, Alonzo Church) SASL Haskell Modula Small. Talk C# C++ Basic C Java Fortran Heritage Reality of Hardware (Memory, John Von Neumann)
Lambda Expressions are All Around Us C# Visual Basic F# Java. Script C++0 x var res = xs. Where(x => x % 2 == 0); Dim res = xs. Where(Function(x) x Mod 2 = 0) let res = xs |> Seq. filter (fun x -> x % 2 = 0); var res = xs. filter(function(x) { return x % 2 == 0; }); auto res = find_if(xs. begin(), xs. end(), [] (int i) { return x % 2 == 0; });
Have We Forgotten About Math? x = x + 1
Defining Functions No notion of time
Aargh… Those Pesky Side-Effects Binds name to value Equality != assignment let equal = sin(0. 0) let sinzero = sin(0. 0) in sinzero = sinzero Not a pure function… let equal = Date. Time. Now let now = Date. Time. Now in now = now Immutability is the default
But We Like Side-Effects So Much… // C# syntax static void Main(string[] args) { Console. Write. Line(args. Length); } (* F# syntax *) let main (args : string array) = printf "%dn" args. Length val main : string array -> unit In Haskell: IO unit I/O is a side-effect Hmm… monads Philip Wadler
Programming in a Functional Style But what’s a function? First class functions Referential transparency Immutable data FP Essence Niceties Type inference Pattern matching Algebraic data types
F# – A General-Purpose Functional Style Language Functional. NET Visual Studio F#
DEMO Functional Programming with Functions
$$$ An Exercise In Purity? Purify yourselves, sinners! Where does F# fit? $ Erik Meijer Simon Peyton-Jones Impure Pure
The world isn’t always typed DYNAMIC PROGRAMMING
REST Dynamic Languages Static Languages Simple and succinct Robust Implicitly typed Performant Meta-programming Intelligent tools No compilation Better scaling JSON Ruby Dynamic vs. Static Python Java. Script
It’s a Dynamic World • Trend on non-schematized data • Remember WSDL, SOAP, XSD? • How about REST, JSON? • The next browser war • Java. Script on the web • Optimized scripting engines • Towards metaprogramming? • Ruby community • Code as data
Dynamic vs. Static a i 32 -bit Typevalue tag 32 -bit value int var a = 0; for (var i = 0; i < n; i++) { a = a + i; } Load type tag of a Load type tag of i Select add operation Load value of a Load value of i ADD instruction Check for overflow Store type tag of result Store value of result Loop back to dispatcher 10 -100 X int Fetch next byte code Call generic add handler
Dynamic VM Advances Interpreter Inline Caching Type Specialization Hidden Classes Tracing Interpretation JIT Compiler Interpretation Operation Dynamic Typing Adaptive JIT Compiler Operation 2 -3 X Dynamic Typing 3 -10 X Operation 10 -100 X Dynamic Typing
. NET Dynamic Programming Iron. Python Iron. Ruby C# VB. NET Others… Dynamic Language Runtime Expression Trees Object Binder Java. Script Binder Dynamic Dispatch Python Binder Call Site Caching Ruby Binder COM Binder
DEMO Dynamic Code and Data
Compiler as a Service Class Meta-programming public Language Object Model Read-Eval-Print Loop Foo Field private DSL Embedding X string Source File code Source code Compiler . NET Assembly Source code 28
Dealing with hardware reality CONCURRENT PROGRAMMING
Taming the Concurrency Monster Can you keep the cores busy? Gordon Moore
Concurrent programming with shared state… …can be hard
Parallel Extensions in. NET 4 Parallel LINQ Coordination Data Structures Task Parallel Library Operating System Threads CPU CPU … CPU
Task Parallel Library in. NET 4 Task<T> Taskoriented Dataoriented PLINQ TPL Rich composition Continuations Coordination and scheduling CDS, etc.
Expressing Parallelism – A Library Approach int[, ] int var for Multiply(int[, ] m 1, int[, ] m 2) { m, n, o; // Left as an exercise res = new int[m, o]; (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] += m 1[i, k] * m 2[k, j]; } } } return res; } Embarrassingly Parallel Lambda expressions to the rescue int[, ] Multiply(int[, ] m 1, int[, ] m 2) { 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] += m 1[i, k] * m 2[k, j]; } } }); return res; }
Expressing Parallelism – A Library Approach Natural Data Parallelism 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); Extension methods to the rescue var source = Enumerable. Range(1, 10000); var res = from x in source. As. Parallel() where f(x) select g(x); res. For. All(x => { Process(x); });
Asynchronous Programming – Low Hanging Fruit? Reactive Ev en tri gg ere d t e ck Pa Your Program Here I/O completed Callbacks ts d e eiv c re Events
Asynchronous Programming Simplified • Don’t block! UI programming, Windows Phone 7, Silverlight • Latency ahead! Dealing with networks, services, cloud A blocking call! var data = Download. Data(…); Process. Data(data); Callback twists your code inside out var data = Download. Data. Async(…, data => { Process. Data(data); }); Visual Studio Async CTP No longer blocking! var data = await Download. Data. Async(…); Process. Data(data); 37
DEMO Using the TPL and the Async CTP
Potential Language Constructs Isolation Purity Immutability
Exciting Times Concurrent • Horse-power of many-core… • …but how to program those? Declarative • Say what you want… • …not how it has to be done? Dynamic • Schematized, static, dynamic… • …so, what’s the sweet spot? Functional • New level of expressiveness… • …how about the essence? 45
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 Download http: //blogs. msdn. com/belux MSDN/Tech. Net Desktop Gadget http: //bit. ly/msdntngadget • Join us on Facebook http: //www. facebook. com/msdnbelux • Linked. In: http: //linkd. in/msdnbelux/ • Twitter: @msdnbelux
Tech. Days 2011 On-Demand • Watch this session on-demand via Channel 9 http: //channel 9. msdn. com/belux • Download to your favorite MP 3 or video player • Get access to slides and recommended resources by the speakers
THANK YOU
- Slides: 41