The DLR on the CLR • Common Language Runtime – CLR: – Common platform for static languages – Facilitates great interop • Dynamic Language Runtime – DLR: – Common platform for dynamic languages – Facilitates great interop
Named arguments • Because Foo(37, 28, 93, 18, true, true, false) is frankly enigmatic • Intended for use in demystifying calls to libraries outside your control, not to excuse designing bad and obscure APIs yourself
Optional parameters • Were evil in 2002 – Versioning considerations • Time heals all wounds – Except those inflicted by DCOM security • Uses OptionalAttribute and DefaultParameterValueAttribute – Does not create an overload – Compatible with Visual Basic
COM interop enhancements • Named and optional arguments support COM APIs that depended heavily on them • “No PIA” – Merges COM interop type definitions into the calling assembly so you don’t need to deploy a PIA – Runtime magic to identify COM types from multiple assemblies • Omitting stupid “ref missing” arguments
Auto-implemented Properties Property FirstName As String Property LastName As String Initializers: Property ID As Integer = -1 Property Suppliers As New List(Of Supplier)
Collection Initializers Dim x As New List(Of Integer) From {1, 2, 3} Dim list As New Dictionary(Of Integer, String) From {{1, “Bart”}, {2, “Lisa”}, {3, “Homer”}} Array Literals: Dim a = {1, 2, 3} 'infers Integer() Dim b = {1, 2, 3.5} 'infers Double()
Statement Lambdas Dim items = {1, 2, 3, 4, 5} Array.ForEach(items, Sub(n) Console.WriteLine(n)) Array.ForEach(items, Sub(n) If n Mod 2 = 0 Then Console.WriteLine(n) End Sub) 'Count the number of even items in the array Dim total = items.Count(Function(n) Return (n Mod 2 = 0) End Function)
Generic Variance Dim apples As IEnumerable(Of Apple) = New List(Of Apple) 'Covariance (Apple inherits from Fruit) Dim fruits As IEnumerable(Of Fruit) = apples 'Contravariance - Func(Of In T, Out R) Dim predicate As Func(Of Fruit, Boolean) = Function(f) f.Color = "Red" apples.Where(predicate)
Threading/Concurrency -> Parallelism On Single Core Machine – Don’t block the UI • Thread Affinity – Async Operations – Synchronization Issues On Multi-core Machine – As above... – ... plus Improve Actual Performance – ... plus create new user experiences