420 likes | 551 Views
Trends in Programming Languages. Bart J.F. De Smet blogs.bartdesmet.net/bart bartde@microsoft.com . The Good Old Days?. Looking at the Past…. More Control Too low-level. Richer Runtimes Ease of Use. Hardware Trends. What about SSD?. x 100,000. What about NUMA?. x 10,000.
E N D
Trends inProgramming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart bartde@microsoft.com
Looking at the Past… More Control Too low-level Richer Runtimes Ease of Use
Hardware Trends What aboutSSD? x 100,000 What about NUMA? x 10,000 What aboutmany-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 Canvas C# and VB vNext Rocket Science? HTML 5 Task Parallel Library User System Internet Explorer 9 Rendering Common Language Runtime DirectX APIs Win32 APIs Established Reality! Time GPU Acceleration Asynchronous I/O
Software Trends But will it blend?
Increasing the level of abstraction Functional Programming
A Different Approach Theory of Computation (Lambda Calculus, Alonzo Church) LISP Heritage CLU ML Miranda Scheme SASL Haskell Modula SmallTalk C C# Java Basic C++ Reality of Hardware (Memory, John Von Neumann) Fortran Heritage
Lambda Expressions are All Around Us C# var res = xs.Where(x => x % 2 == 0); Visual Basic Dim res = xs.Where(Function(x) x Mod 2 = 0) F# let res = xs |> Seq.filter (fun x -> x % 2 = 0); 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
Have We Forgotten About Math? x = x + 1
Defining Functions No notion of time
Aargh… Those Pesky Side-Effects Immutability is the default Binds name to value Equality != assignment letequal = sin(0.0) = sin(0.0) letsinzero = sin(0.0)insinzero = sinzero Not a pure function… letequal = DateTime.Now = DateTime.Now letnow= DateTime.Nowin now = now
But We Like Side-Effects So Much… // C# syntax static void Main(string[] args) { Console.WriteLine(args.Length); } (* F# syntax *) letmain(args:stringarray) = printf"%d\n"args.Length valmain:stringarray->unit I/O is a side-effect Hmm… monads In Haskell: IO unit Philip Wadler
Programming in a Functional Style But what’s a function? First class functions Referentialtransparency Immutabledata FP Essence Niceties Typeinference Patternmatching Algebraic data types
Functional Programming Programming with Functions
An Exercise In Purity? Purify yourselves, sinners! $$$ Where doesF# fit? Erik Meijer Simon Peyton-Jones $ Pure Impure
The world isn’t always typed DYNAMIC Programming
Dynamic vs. Static JSON Python REST JavaScript Ruby
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
Dynamic vs. Static a i Type tag 32-bit value Type tag 32-bit value Fetch next byte code Call generic add handler 32-bit value 32-bit value Load type tag of a Load type tag of i Select add operation Load value of a Load value of i int int 10-100 X var a = 0;for (vari = 0; i < n; i++){a = a + i;} ADD instruction Check for overflow Store type tag of result Store value of result Loop back to dispatcher
Dynamic VM Advances Interpreter Inline Caching Type Specialization Hidden Classes Tracing Interpretation JIT Compiler DynamicTyping DynamicTyping AdaptiveJIT Compiler 10-100 X 3-10 X 2-3 X Operation Operation Operation DynamicTyping DynamicTyping Interpretation
.NET Dynamic Programming IronPython IronRuby C# VB.NET Others… Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching ObjectBinder JavaScriptBinder PythonBinder RubyBinder COMBinder
Compiler as a Service Meta-programming Read-Eval-Print Loop Class public Foo Language Object Model Field DSL Embedding private X string Compiler Compiler SourceFile .NET Assembly Source code Source code Source code Source code
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 Task Parallel Library Coordination Data Structures Operating System Threads … CPU CPU CPU CPU
Task Parallel Library in .NET 4 Task<T> PLINQ Continuations CDS, etc.
Expressing Parallelism – A Library Approach int[,] Multiply(int[,] m1, int[,] m2) { int m, n, o; // Left as an exercise var res = newint[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 int[,] Multiply(int[,] m1, int[,] m2) { int m, n, o; // Left as an exercise var res = newint[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; }
Expressing Parallelism – A Library Approach Natural Data Parallelism varsource = 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 varsource = Enumerable.Range(1, 10000); var res = from x insource.AsParallel() where f(x) select g(x); res.ForAll(x => { Process(x); });
Asynchronous Programming – Low Hanging Fruit? Reactive Events triggered Packetreceived Your Program Here I/O completed Callbacks Events
Asynchronous Programming Simplified • Don’t block! UI programming, Windows Phone 7, Silverlight • Latency ahead! Dealing with networks, services, cloud A blocking call! Callback twists yourcode inside out vardata = DownloadData(…); ProcessData(data); vardata = DownloadDataAsync(…, data => { ProcessData(data); }); Visual StudioAsync CTP No longer blocking! vardata = awaitDownloadDataAsync(…); ProcessData(data);
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 bloghttp://blogs.msdn.com/belux • Join us on Facebookhttp://www.facebook.com/msdnbehttp://www.facebook.com/msdnbelux • LinkedIn: http://linkd.in/msdnbelux/ • Twitter: @msdnbelux DownloadMSDN/TechNet Desktop Gadgethttp://bit.ly/msdntngadget
TechDays 2011 On-Demand • Watchthis session on-demand via Channel9http://channel9.msdn.com/belux • Download to your favorite MP3 or video player • Get access to slides and recommended resources by the speakers