AmirdhaGopalRajendran<br />xConf<br />Thoughtworks, Chennai<br />.NET Framework 4.0 with Visual Studio 2010<br />The evolu...
Setting the Scene<br />.NET Roadmap<br />Overview of Framework 4.0 Universe<br />Overview of Visual Studio 2010<br />Trend...
.NET Roadmap<br />SP1<br />3.5<br />3.0<br />.NET 1.0<br />.NET 1.1<br />.NET 2.0<br />.NET 4.0<br />2002<br />2003<br />2...
Trends in Programming Languages<br />
Dynamic Language Runtime<br />
Why a “Dynamic Language Runtime”?<br />Dynamically-Typed<br />Ruby<br />Python<br />Statically-Typed<br />VB<br />C#<br />...
Why a “Dynamic Language Runtime”?<br />Dynamically-Typed<br />Ruby<br />Python<br />Statically-Typed<br />VB<br />Dynamic ...
Dynamic Language Runtime<br />.NET ?.?<br />DLR2<br />Script Hosting<br />Compiler as<br />a Service<br />???<br />.NET 4....
Dynamic Language Runtime<br />IronPython<br />IronRuby<br />C#<br />VB.NET<br />Others…<br />Dynamic Language Runtime<br /...
The Evolution of C#<br />C# 4.0<br />Dynamic Programming<br />C# 3.0<br />Language Integrated Query<br />C# 2.0<br />Gener...
dynamic<br />Calculator calc = GetCalculator();<br />int sum = calc.Add(10, 20);<br />object calc = GetCalculator();<br />...
Dynamically Typed Objects<br />Compile-time typedynamic<br />Run-time typeSystem.Int32<br />dynamic x = 1;<br />dynamic y ...
 At run-time, actual type(s) substituted for dynamic
 Static result type of operation is dynamic</li></li></ul><li>Parallel Programming<br />
Parallel Programming<br />Tools<br />Managed Languages<br />Axum<br />Visual F#<br />Visual Studio 2010<br />Parallel<br /...
Minimizing the Overhead of Parallelism<br />The Argument:<br />Parallelization demands division<br />Executing work items ...
Global Queue<br />Worker Thread 1<br />Worker Thread 1<br />ThreadPool in .NET 3.5<br />…<br />Item 4<br />Item 5<br />Pro...
Idle Thread Retirement</li></li></ul><li>ThreadPool in .NET 4<br />Local<br />Work-Stealing Queue<br />Local Work-Stealing...
Idle Thread Retirement
Hill-climbing</li></li></ul><li>Rev Up Your Loops<br />Control flow is a primary source of work<br />Parallelizable when i...
C# Language Features<br />Co- and Contra-Variance<br />Optional and Named Parameters<br />
Co- and Contra-variance<br />.NET arrays are co-variant<br />string[] strings = GetStringArray();<br />Process(strings);<b...
Safe Co- and Contra-variance<br />publicinterfaceIEnumerable<T><br />{<br />IEnumerator<T> GetEnumerator();<br />}<br />pu...
Variance in C# 4.0<br />Supported for interface and delegate types<br />“Statically checked definition-site variance”<br /...
Variance in .NET Framework 4.0<br />Interfaces<br />System.Collections.Generic.IEnumerable<out T><br />System.Collections....
Optional and Named Parameters<br />Primary method<br />publicStreamReaderOpenTextFile(<br />    string path,<br />    Enco...
Optional and Named Parameters<br />Optional parameters<br />publicStreamReaderOpenTextFile(<br />    string path,<br />   ...
New Collection Types and DataStructures<br />Tuple<br />SortedSet<br />BigInteger<br />
In mathematics, a tuple is a sequence (or ordered list) of finite length.<br />Used in F# & Python, but also easy to use n...
Collection  of UNIQUEelements in SORTED Order.<br />Sorted Set<br />varsetRange = newSortedSet<int>() {2,5,6,2,1,4,8 };<br...
Used by both F# & Python.<br />Big Integer<br />BigIntegeri = new BigInteger(ulong.MaxValue.ToString());<br />BigIntegeriS...
Native Code Interoperability<br />Managed Extensibility Framework<br />System.Numerics.Complex<br />Tail Recursion (for F#...
Upcoming SlideShare
Loading in …5
×

.Net 4 Framework 2010

2,263 views
2,180 views

Published on

Major features of .NET 4.0

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

No Downloads
Views
Total views
2,263
On SlideShare
0
From Embeds
0
Number of Embeds
42
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • CLR bridge for dynamic languages.Iron – Implementation Running On How it works?1. Dynamic Code Generation2. Dynamic Type System3. Dynamic Method Dispatch
  • Multi-core chip – eight or fewer homogeneous cores in one microprocessor package.Many-core chip – more than eight possibly heterogeneous cores in one microsprocessor package. Good Parallel Implementation – One thread per core.Concurrency profiler
  • .Net 4 Framework 2010

    1. 1. AmirdhaGopalRajendran<br />xConf<br />Thoughtworks, Chennai<br />.NET Framework 4.0 with Visual Studio 2010<br />The evolution of a general purpose software development framework<br />
    2. 2. Setting the Scene<br />.NET Roadmap<br />Overview of Framework 4.0 Universe<br />Overview of Visual Studio 2010<br />Trends in Programming Languages<br />Dynamic Language Runtime<br />Parallel Programming<br />C# Language Features <br />Covariance & ContraVariance<br />Optional and Named Parameters<br />New Collection Types & Data structures<br />Tuple<br />SortedSet<br />BigInteger<br />Left overs<br />References<br />Introduction<br />
    3. 3. .NET Roadmap<br />SP1<br />3.5<br />3.0<br />.NET 1.0<br />.NET 1.1<br />.NET 2.0<br />.NET 4.0<br />2002<br />2003<br />2010 RC<br />2005-08<br />CLR 1.0<br />CLR 1.1<br />CLR 2.0<br />CLR 4.0<br />
    4. 4.
    5. 5.
    6. 6.
    7. 7.
    8. 8. Trends in Programming Languages<br />
    9. 9. Dynamic Language Runtime<br />
    10. 10. Why a “Dynamic Language Runtime”?<br />Dynamically-Typed<br />Ruby<br />Python<br />Statically-Typed<br />VB<br />C#<br />Common Language Runtime<br />
    11. 11. Why a “Dynamic Language Runtime”?<br />Dynamically-Typed<br />Ruby<br />Python<br />Statically-Typed<br />VB<br />Dynamic Language Runtime<br />C#<br />Common Language Runtime<br />
    12. 12. Dynamic Language Runtime<br />.NET ?.?<br />DLR2<br />Script Hosting<br />Compiler as<br />a Service<br />???<br />.NET 4.0<br />DLR<br />Expression<br />Trees v2<br />Call Site Caching<br />Dynamic<br />Dispatch<br />.NET 3.5<br />LINQ<br />Expression<br />Trees<br />Extension<br />Methods<br />Silverlight<br />.NET 2.0<br />Generics<br />In Runtime<br />Fast<br />Delegates<br />Dynamic<br />Methods<br />.NET 1.0<br />GC<br />Reflection<br />JIT<br />BCL<br />Dynamic<br />Codegen<br />Verifier<br />Sandbox<br />
    13. 13. Dynamic Language Runtime<br />IronPython<br />IronRuby<br />C#<br />VB.NET<br />Others…<br />Dynamic Language Runtime<br />Expression Trees<br />Dynamic Dispatch<br />Call Site Caching<br />PythonBinder<br />RubyBinder<br />COMBinder<br />JavaScriptBinder<br />ObjectBinder<br />
    14. 14. The Evolution of C#<br />C# 4.0<br />Dynamic Programming<br />C# 3.0<br />Language Integrated Query<br />C# 2.0<br />Generics<br />C# 1.0<br />Managed Code<br />
    15. 15. dynamic<br />Calculator calc = GetCalculator();<br />int sum = calc.Add(10, 20);<br />object calc = GetCalculator();<br />TypecalcType = calc.GetType();<br />object res = calcType.InvokeMember("Add",<br />BindingFlags.InvokeMethod, null,<br />newobject[] { 10, 20 });<br />int sum = Convert.ToInt32(res);<br />ScriptObject calc = GetCalculator();<br />object res = calc.Invoke("Add", 10, 20);<br />int sum = Convert.ToInt32(res);<br />Statically typed to be dynamic<br />dynamic calc = GetCalculator();<br />int sum = calc.Add(10, 20);<br />Dynamic method invocation<br />Dynamic conversion<br />
    16. 16. Dynamically Typed Objects<br />Compile-time typedynamic<br />Run-time typeSystem.Int32<br />dynamic x = 1;<br />dynamic y = "Hello";<br />dynamic z = newList<int> { 1, 2, 3 };<br />When operand(s) are dynamic…<br /><ul><li> Member selection deferred to run-time
    17. 17. At run-time, actual type(s) substituted for dynamic
    18. 18. Static result type of operation is dynamic</li></li></ul><li>Parallel Programming<br />
    19. 19. Parallel Programming<br />Tools<br />Managed Languages<br />Axum<br />Visual F#<br />Visual Studio 2010<br />Parallel<br />Debugger Windows<br />Native Libraries<br />ManagedLibraries<br />DryadLINQ<br />Async<br />AgentsLibrary<br />Parallel Pattern Library<br />Profiler Concurrency<br />Analysis<br />Parallel LINQ<br />Rx<br />Task ParallelLibrary<br />Data Structures<br />Data Structures<br />Microsoft<br />Research<br />Native Concurrency Runtime<br />Task Scheduler<br />Race Detection<br />Managed Concurrency Runtime<br />Resource Manager<br />ThreadPool<br />Fuzzing<br />Operating System<br />Threads<br />UMS Threads<br />HPC Server<br />Windows 7 / Server 2008 R2<br />Research / Incubation<br />Visual Studio 2010 / .NET 4<br />Key:<br />
    20. 20. Minimizing the Overhead of Parallelism<br />The Argument:<br />Parallelization demands division<br />Executing work items has overhead<br />Results in increased overhead to work ratio<br />We must decrease overhead<br />Overhead<br />Overhead<br />Overhead<br />Work<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />Overhead<br />
    21. 21. Global Queue<br />Worker Thread 1<br />Worker Thread 1<br />ThreadPool in .NET 3.5<br />…<br />Item 4<br />Item 5<br />Program Thread<br />Item 1<br />Item 2<br />Item 3<br />Item 6<br />Thread Management:<br /><ul><li>Starvation Detection
    22. 22. Idle Thread Retirement</li></li></ul><li>ThreadPool in .NET 4<br />Local<br />Work-Stealing Queue<br />Local Work-Stealing Queue<br />Lock-Free<br />Global Queue<br />…<br />Worker Thread 1<br />Worker Thread p<br />…<br />Task 6<br />Task 3<br />Program Thread<br />Task 4<br />Task 1<br />Task 5<br />Task 2<br />Thread Management:<br /><ul><li>Starvation Detection
    23. 23. Idle Thread Retirement
    24. 24. Hill-climbing</li></li></ul><li>Rev Up Your Loops<br />Control flow is a primary source of work<br />Parallelizable when iterations are (or can be made) independent<br />Synchronous<br />All work quiesces, regularly or exceptionally<br />Lots of knobs<br />Cancelation, breaking, task-local state, custom partitioning, scheduling, degree of parallelism<br />foreach(var item in data) <br />{<br /> work(item);<br />}<br />for (int i = 0; i < n; i++) <br />{<br /> work(i);<br />}<br />StatementA();<br />StatementB;<br />StatementC();<br />Parallel.ForEach(data, item=><br />{<br /> work(item);<br />});<br />Parallel.For(0, n, i=> <br />{<br /> work(i);<br />});<br />Parallel.Invoke(<br /> () => StatementA(),<br /> () => StatementB,<br /> () => StatementC());<br />from item in shows.AsParallel()<br />where item.Description.Contains(keyword)<br />select item;<br />
    25. 25. C# Language Features<br />Co- and Contra-Variance<br />Optional and Named Parameters<br />
    26. 26. Co- and Contra-variance<br />.NET arrays are co-variant<br />string[] strings = GetStringArray();<br />Process(strings);<br />…but not safelyco-variant<br />void Process(object[] objects) { … }<br />void Process(object[] objects) {<br /> objects[0] = "Hello"; // Ok<br /> objects[1] = newButton(); // Exception!<br />}<br />Until now, C# generics have been invariant<br />List<string> strings = GetStringList();<br />Process(strings);<br />C# 4.0 supports safe co- and contra-variance<br />void Process(IEnumerable<object> objects) { … }<br />void Process(IEnumerable<object> objects) {<br />// IEnumerable<T> is read-only and<br />// therefore safely co-variant<br />}<br />
    27. 27. Safe Co- and Contra-variance<br />publicinterfaceIEnumerable<T><br />{<br />IEnumerator<T> GetEnumerator();<br />}<br />publicinterfaceIEnumerable<out T><br />{<br />IEnumerator<T> GetEnumerator();<br />}<br />out= Co-variantOutput positions only<br />Can be treated asless derived<br />publicinterfaceIEnumerator<T><br />{<br /> T Current { get; }<br />boolMoveNext();<br />}<br />publicinterfaceIEnumerator<out T><br />{<br /> T Current { get; }<br />boolMoveNext();<br />}<br />IEnumerable<string> strings = GetStrings();<br />IEnumerable<object> objects = strings;<br />in= Contra-variantInput positions only<br />publicinterfaceIComparer<T><br />{<br />int Compare(T x, T y);<br />}<br />publicinterfaceIComparer<in T><br />{<br />int Compare(T x, T y);<br />}<br />Can be treated asmore derived<br />IComparer<object> objComp = GetComparer();<br />IComparer<string> strComp = objComp;<br />
    28. 28. Variance in C# 4.0<br />Supported for interface and delegate types<br />“Statically checked definition-site variance”<br />Value types are always invariant<br />IEnumerable<int> is notIEnumerable<object><br />Similar to existing rules for arrays<br />
    29. 29. Variance in .NET Framework 4.0<br />Interfaces<br />System.Collections.Generic.IEnumerable<out T><br />System.Collections.Generic.IEnumerator<out T><br />System.Linq.IQueryable<out T><br />System.Collections.Generic.IComparer<in T><br />System.Collections.Generic.IEqualityComparer<in T><br />System.IComparable<in T><br />Delegates<br />System.Func<in T, …, out R><br />System.Action<in T, …><br />System.Predicate<in T><br />System.Comparison<in T><br />System.EventHandler<in T><br />
    30. 30. Optional and Named Parameters<br />Primary method<br />publicStreamReaderOpenTextFile(<br /> string path,<br /> Encodingencoding,<br />booldetectEncoding,<br />intbufferSize);<br />Secondary overloads<br />publicStreamReaderOpenTextFile(<br /> string path,<br /> Encodingencoding,<br />booldetectEncoding);<br />publicStreamReaderOpenTextFile(<br /> string path,<br /> Encodingencoding);<br />publicStreamReaderOpenTextFile(<br /> string path);<br />Call primary with default values<br />
    31. 31. Optional and Named Parameters<br />Optional parameters<br />publicStreamReaderOpenTextFile(<br /> string path,<br /> Encodingencoding,<br />booldetectEncoding,<br />intbufferSize);<br />publicStreamReaderOpenTextFile(<br /> string path,<br /> Encodingencoding = null,<br />booldetectEncoding = true,<br />intbufferSize = 1024);<br />Named argument<br />OpenTextFile("foo.txt", Encoding.UTF8);<br />OpenTextFile("foo.txt", Encoding.UTF8, bufferSize: 4096);<br />Arguments evaluated in order written<br />Named arguments can appear in any order<br />Named arguments must be last<br />OpenTextFile(<br />bufferSize: 4096,<br /> path: "foo.txt",<br />detectEncoding: false);<br />Non-optional must be specified<br />
    32. 32. New Collection Types and DataStructures<br />Tuple<br />SortedSet<br />BigInteger<br />
    33. 33. In mathematics, a tuple is a sequence (or ordered list) of finite length.<br />Used in F# & Python, but also easy to use now from C#<br />Tuple<br />publicTuple<Int32, Int32> DivAndRemainder(Int32i, Int32 j) <br />{<br /> returnnewTuple.Create(i/j, i%j);<br />}<br /> <br />// An example of someone accessing items in a tuple. <br />for (Int16i = 0; i <= 25; i++) {<br />for (Int16j = 1; j <= 5; j++) {<br />vartuple = DivAndRemainder(i,j);<br />Console.WriteLine("{0} {1} {2} {3} ", <br />i, j, tuple.item1, tuple.item2);<br />}<br />
    34. 34. Collection of UNIQUEelements in SORTED Order.<br />Sorted Set<br />varsetRange = newSortedSet<int>() {2,5,6,2,1,4,8 };<br />foreach(variinsetRange){ Console.Write(i); }<br />//output: 124568<br />
    35. 35. Used by both F# & Python.<br />Big Integer<br />BigIntegeri = new BigInteger(ulong.MaxValue.ToString());<br />BigIntegeriSquared = i.multiply(i); <br />Console.WriteLine("i: " + i); <br />Console.WriteLine("i^2: " + iSquared);<br />i: 18446744073709551615 <br />i^2: 340282366920938463426481119284349108225<br />
    36. 36. Native Code Interoperability<br />Managed Extensibility Framework<br />System.Numerics.Complex<br />Tail Recursion (for F#)<br />Code Contract<br />In-Process Side-by-Side<br />GC Improvements<br />Profiling Improvements<br />Debugging Improvements<br />Etc…<br />Left Overs<br />
    37. 37. Dynamic Language Runtime<br />Code Plex: http://dlr.codeplex.com/<br />Deep Dive: http://channel9.msdn.com/pdc2008/TL10/<br />Parallel Programming<br />Manycore and .NET 4.0: http://microsoftpdc.com/Sessions/P09-09<br />Samples: http://code.msdn.microsoft.com/ParExtSamples<br />C# Language Features<br />Anders Talk (Must Watch): http://channel9.msdn.com/pdc2008/TL16/<br />References<br />
    38. 38. Thank you<br />

    ×