Trends in Programming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart [email protected].
-
Upload
ashlyn-manning -
Category
Documents
-
view
217 -
download
3
Transcript of Trends in Programming Languages Bart J.F. De Smet blogs.bartdesmet.net/bart [email protected].
Trends inProgramming LanguagesBart J.F. De Smetblogs.bartdesmet.net/[email protected]
Looking at the Past…
Assembler
Procedural
ObjectsManaged
Richer RuntimesEase of Use
More ControlToo low-level
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)
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
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?FunctionalBut w
ill it
ble
nd?
A Different Approach
Theory of Computation(Lambda Calculus, Alonzo Church)
LISP Heritage
Reality of Hardware(Memory, John Von Neumann)
Fortran Heritage
Basi
c
SmallTalk
ModulaC C++Java
C#
Sche
me
SASLHaskell
ML
Miranda
CLU
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
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.Nowlet now = DateTime.Now in now = now
Not a pure function…
Immutability is the default
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.Lengthval main : string array -> unit
In Haskell: IO unit
I/O is a side-effect
Philip Wadler
Hmm… monads
Programming in a Functional Style
FP
First class functions
Immutabledata
Referentialtransparency
Algebraic data types
Typeinference
Patternmatching
Essence
Niceties
But what’s a function?
An Exercise In Purity?$$
$$
Impure Pure
Purify yourselves, sinners!
Erik Meijer Simon Peyton-JonesWhere does
F# fit?
Dynamic vs. Static
DynamicLanguages
Simple and succinct
Implicitly typed
Meta-programming
No compilation
StaticLanguages
Robust
Performant
Intelligent tools
Better scaling
REST
JavaScript
Ruby
JSON
Python
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
32-bit value 32-bit valueType tag
32-bit value
Type tag
32-bit value
Loop back to dispatcher
Fetch next byte codeCall generic add handler
Check for overflowStore type tag of result
Store value of result
Load type tag of aLoad type tag of i
Select add operationLoad value of aLoad 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 int
a i
Dynamic VM Advances
Interpretation
Interpretation
DynamicTyping
DynamicTyping
Operation
10-100 X
Interpreter
DynamicTyping
DynamicTyping
Operation
3-10 X
JIT Compiler
Operation
2-3 X
AdaptiveJIT Compiler
Inline CachingType Specialization
Hidden ClassesTracing
PythonBinder
RubyBinder
COMBinder
JavaScriptBinder
ObjectBinder
.NET Dynamic Programming
Dynamic Language Runtime
Expression Trees Dynamic Dispatch Call Site Caching
IronPython IronRuby C# VB.NET Others…
Compiler as a Service
28
Class
Field
public Foo
private
string
X
CompilerCompilerSource codeSource code
SourceFile
Source codeSource code
.NET Assembly
Meta-programming Read-Eval-Print Loop
LanguageObject Model
DSL Embedding
Operating System Threads
Parallel Extensions in .NET 4
Parallel LINQ
Task Parallel Library Coordination Data Structures
CPU CPU …CPU CPU
Task-oriented
Data-oriented
Richcomposition
Coordinationand scheduling
TPL
Task<T> PLINQ
CDS, etc.Continuations
Task Parallel Library in .NET 4
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
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
Asynchronous Programming – Low Hanging Fruit?
Your Program Here
Eventstriggered
I/O
completed
Packet
received
EventsCallbacks
Reactive
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 yourcode inside out
var data = DownloadDataAsync(…, data => { ProcessData(data);});
var data = await DownloadDataAsync(…);ProcessData(data);
No longer blocking!Visual Studio
Async CTP
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
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
Download MSDN/TechNet Desktop Gadget
http://bit.ly/msdntngadget
TechDays 2011 On-Demand
• Watch this 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