TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub...

46
TeSLa research product

Transcript of TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub...

Page 1: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

TeSLa

research product

Page 2: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Why The $@#%! Visual Basic

Imports SySTem.STriNg

Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End SubEnd Module

Case insensitive

Static class

Class imports

Page 3: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Why The $@#%! Visual Basic

Class Dog Public Event Bark()End Class

Dim WithEvents D As New Dog()

Sub OnBark() Handles D.Bark Console.WriteLine("Call 911")End Sub

DeclarativeEvent Handling

"AOP"

Page 4: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Why The $@#%! Visual Basic

Function F(X As Integer, _ Optional Flag As Boolean = False) _ As String …End Function

F (Flag := True, X := 4711)

Optional parameters

Named arguments

Page 5: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Why The $@#%! Visual Basic

Class Dog Public Event Bark()

Public Default Property Toys(Name As String) _ As Object Get … End Get

Set (Value As Object) … End Set End PropertyEnd Class

Line continuations

Indexed Properties

Page 6: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

With Scope(Power is in the ".")

Why The $@#%! Visual Basic

Dim D As New Dog()

With D .Toys("Bone") = New Bone() .Toys!Cat = CatchNeighboursCat() Console.WriteLine(.Toys("Ball").Color)End With

With Statement

Late binding

Late binding

Page 7: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Late Binding

K = J+3

For I=0 To 10 Console.WriteLine(I)Next

Dim X As String = 4711

Function F(X) Return X+3End Function

Implicit Explicit Conversions

Option Implicit

Types Optional

Page 8: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim WithEvents B As New Button()

Sub OnClick(sender As Object, e As EventArgs) _ Handles B.Click End Sub

Sub RelaxedOnClick(sender As Object, e As Object) _ Handles B.Click End Sub

Can call it can handle it

Relaxed delegates

Page 9: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Delegate Function F(A As S) As T

Function G(B As P) As Q

New F(AddressOf G)New F(Function(A) CType(G(CType(A,P)),T)

Relaxed delegates

Conversion stub

Page 10: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

<Runtime.CompilerServices.Extension()> _Function FindName(Source As Object, Name As String) As ObjectOn Error Resume NextIf Source.Name = Name Then Return SourceEnd IfDim Children As Object = Source.ChildrenIf Children IsNot Nothing Then For Each Child As Object In Children FindName = FindName(Child, Name) If FindName IsNot Nothing Then Return FindName End If NextEnd IfReturn NothingEnd Function

"AOP"

Extension Methods

Why The $@#%! Visual Basic

Unstructured Exception Handling

Late binding

Page 11: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Late Binding!

G |- e As S ~~> e’G |- a As T ~~> a’S•m(T) As R ~~> f----------------------------------G |- e.m(a) As R ~~> f(e’,a’)

Type Rule For Early-BoundMethod Invocation

Page 12: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Late Binding!

G |- e As Object ~~> e’G |- a As T ~~> a’T <: Object ~~> g-----------------------------G |- e.m(a) <: Object ~~> latecall("m", e’, g(a’))

Type Rule For Late-BoundMethod Invocation

Page 13: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Late Binding!

s.GetType() S, t.GetType() T

S•m(T) <: R ~~> fR <: Object ~~> h----------------------------latecall(m,s,t) h(f(s,t))

Operational Semantics For Late-Bound Call

VB has multi-methods!

Page 14: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Late Binding

Class A Sub F(X As String) WriteLine("F(String)") End Sub Sub F(X As Object) WriteLine("F(Object)") End Sub Sub Main() Dim A = New A() Dim S As Object = "Hello" A.F(S) REM Early F(Object) CObj(A).F(S) REM Late F(String) End SubEnd Class

Type Inference

Imports System.Console

Page 15: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Meta-circular interpreter

ℰ[ A+B ]=Add(ℰ[ A ], ℰ[ B ]) ℰ[ A.m(B) ]= Call(ℰ[ m ], ℰ[ A ], ℰ[ B ])

Self interpretation is litmus test for dynamic

language

Page 16: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

G |- e <: Object ~~> e’G |- a <: T ~~> a’T <: Object ~~> f G |- m <: String ~~> m'------------------------------------------------------G |- e.(m)(a) <: Object ~~> latecall(m', e’, f(a’))

Replace Constants By Variables

Later binding

Page 17: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Later Binding

Class A Sub F(X As String) WriteLine("F(String)") End Sub Sub F(X As Object) WriteLine("F(Object)") End Sub Sub Main() Dim A = New A() Dim S As Object = "Hello" A.(Console.ReadLine())(S) End SubEnd Class

Page 18: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Static Typing Where Possible

Dynamic Typing Where

Necessary

VB as the ultimate scripting language

Page 19: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

e = 8 + 9 \ + 10

d = 4 + 5 + 6 + 7

def options(a=99, b=a+1) [a,b]end

redirect_to :action => 'show', :id => 4711

Ruby

Smart "inference"

Line continuation

Default arguments

Named arguments via hashes

Page 20: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

LINQ Project== monad comprehensions in C# & VB

VB 9 C# 3.0 …

StandardQuery

Operators

DLinq(relational)

XLinq(xml)

LINQ Framework

Page 21: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Swartz, SETL 1970; Burstall and Darlington, NPL 1977; Turner, KRC 1981; …. Haskell, Python, Scala, …

Write programs using mathematical ZF set comprehensions syntax.

Wadler 1989

List comprehensions are related to the relational calculus.

Wadler 1992

List comprehensions are a special case of monad comprehensions.

The Origins of LINQ

Page 22: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

SELECT X.FirstName, X.LastNameFROM Authors AS XWHERE X.City = 'OakLand'

oaklands = do{ x <- table authors ; restrict (x!city .==. constant "Oakland") ; project ( au_fname = x!au_fname , au_lname = x!au_lname ) }

HaskellDb Query Monad (1997)

Query monad

intentional representation for expressions

Page 23: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone };

var contacts = customers .Where(c => c.State == "WA") .Select(c => new{c.Name, c.Phone});

Query Comprensions In C# 3.0

Syntactic sugar over standard

query operations

-expression

Type inference

Page 24: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprensions In Visual Basic 9

Dim Squares = From N In Range(0,99) Select N*N

Dim Pairs = From N In Range(0,9) From C In "ABCDEFGHIJ" Select N, C

Dim Evens = From N In (0,99) Where N Mod 2 = 0 Select N

Dim ByDigit = From N In (0,99) Group By N Mod 10 Select Key, It

Page 25: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim Contacts = From C In Customers Where C.State = "WA" Select C.Name, C.Phone Dim Contacts = _ Customers. Where(Function(C) C.State = "WA"). Select(New With { .Name = C.Name, .Phone = C.Phone })

In Visual Basic 9

Page 26: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprensions In Visual Basic 9

Dim MyCDs As IEnumerable(Of _ { Title As String , Artist As String }) = _ From CD In MyMusic Where CD.Genre IsNot Classic Group By Genre = CD.Genre Where Count(CD) > 10 Select Group(CD.Title, CD.Artist)

Aggregate comprehensions

Page 27: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprehensions

X

X,Y

From Y In F(X)

Joined

Xs.SelectMany((X) _

F(X).Select((Y)_ New {X,Y}))

Compiled To Standard

Query Operators

Page 28: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprehensions

X,Y

Order By F(X,Y)

X,Y

Sorted

XYs.OrderBy((XY) _

F(XY.X, XY.Y))

Page 29: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprehensions

X,Y

X,Y

Where P(X,Y)

Filtered

XYs.Where((XY) _ P(XY.X, XY.Y))

Page 30: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprehensions

A,B

Select A = F(X,Y), B = G(X,Y)

X,Y projected

XYs.Select((XY) _ New {A = F(XY.X, XY.Y), _ B = F(XY.X, XY.Y) })

Page 31: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Query Comprehensions

A,B,

X,Y

Group By A = G(X,Y), B = H(X,Y)

groupedX,Y

XYs.GroupBy((XY) _ New {A = G(XY.X, XY.Y), _ B = H(XY.X, XY.Y) })

Page 32: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Extension Methods

static class Integer { static void Times (this int x, Action<int> f){ for(var i = 0; i < x; i++) f(i); }

3.Times((x) => { Console.WriteLine(x);}

Page 33: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

var contacts = customers .Where(c => c.State == "WA") .Select(c => new{c.Name, c.Phone});

static class System.Query{ public static IEnumerable<T> Where<T>(this IEnumerable<T> src, Func<T, bool>> p); …}

Extension Methods

Extension method for IEnumerable<T>

IEnumerable<Customer>

Page 34: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim Contacts = _ Customers.Where(P).Select(R)

Module MyExtensions<Runtime.CompilerServices.Extension()> _ Function Where(Of T)( _ [Me] As IEnumerable(Of T), _ P As Func(Of T, Boolean)) _ As IEnumerable(Of T) …End Module

In Visual Basic 9

Just CA

Page 35: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

var contacts = customers .Where(c => c.State == "WA") .Select(c => new{c.Name, c.Phone});

class Table<T>: IEnumerable<T>{ public Table<T> Where(Expression <Func<T, bool>> p); …}

Expression Trees

Intensional representation of delegate

Table<Customer>

Page 36: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim F As Expr = Function(X)X+3

Dim G = F.Compile()

Dim Z = G(5)

Expression Trees

Compile to delegate

Convert to expression tree by type

Execute

Page 37: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone };

var Joe = new Person{ Name = “Joe”, Age = 42, Address = { Street = “1th St”, City = “Seattle” }}

Anonymous types,Object initializers

Anonymous types

Initialize RO member

Object Initializers

Page 38: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim Contacts As IEnumerable(Of _ { Name As String, Phone As Integer } = From c In customers _ Where C.State == "WA“ _ Select c.Name, c.Phone

Dim Joe As Person = New With { _ .Name = “Joe”, .Age = 42, _ Address With { _ .Street = “1th St”, .City = “Seattle” }}

In Visual Basic 9

Anonymous types

Syntax new

Page 39: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim S1 As String? = NothingDim S2 As String? = “Hello”

Dim S3 = S1+S2

Nullable

Null propagating +

In VB Nothing is default

Page 40: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

XML DOM

Dim PO As New XmlDocument

Dim purchaseOrder As XmlElement = _ PO.CreateElement("purchaseOrder")PO.AppendChild(purchaseOrder)

Dim orderDate As XmlAttribute = PO.CreateAttribute("orderDate")orderDate.Value = "1999-10-20"purchaseOrder.Attributes.Append(orderDate)

Dim shipTo As XmlElement = PO.CreateElement("shipTo")purchaseOrder.AppendChild(shipTo)

Dim country As XmlAttribute = PO.CreateAttribute("country")country.Value = "US"shipTo.Attributes.Append(country)

What does this

program do?

Page 41: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim Item = _New XElement("item", _ New XAttribute("partNum", "926-AA"), _ New XElement("productName", “…"), _ New XElement("quantity", 1), _ New XElement("price", 39.98), _ New XElement("shipDate", "1999-05-21"))))

Functional (expression-based) construction

Context-free (no document scope)

Simple

XLinq API

Page 42: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

table :: TABLEtable = <TABLE border="1"> <% mkRows cells %> </TABLE>

cells :: [[(Int,Int)]]cells = [[ (x,y) | x <- [1..16] ] | y <- [1..16] ]

mkRows :: [[(Int,Int)]] -> [TR]mkRows = map $ \cs -> <TR><% mkColums cs %></TR>

mkColumns :: [(Int,Int)] -> [TD]mkColums = map $ \c -> <TD bgcolor=(color c)><% c %></TD>

Haskell Server PagesXHTML Literals (1998)

ASP-style embedding

Translated to universal DOM representation

Page 43: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Dim PO = <purchaseOrder orderDate=(System.DateTime.Today)> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <%= BillTo %> <items> <%= Select <item partNum=<%= O.PartID %>>

<productName> <%= O.Product %>

</productName> <quantity>

<%= O.Quantity %> </quantity> <price>

<%= O.Price %></price>

</item> From O In Orders Where O.Name = "Robert Smith" %> </items>

</purchaseOrder>

Translated to XLinq constructor

calls

ASP-style embedding

Includes full namespace

support

Page 44: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

Late binding over XML

Child axis BillTo.<street>

BillTo.Elements(“street”)

Attribute axis BillTo.@country

BillTo.Attributes(“country”)

Descendants axis PO...<item>

PO.Descendants(“item”)

Page 45: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

• Tools & IDE• Type system & Language extensions• Runtime & Library support• Transactions everywhere

Tesla

Page 46: TeSLa researchproduct. Why The $@#%! Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.

VB IsNot C#

VB = static typing where possible, dynamic typing where necessary.

Conclusion