A Programmable Web Framework John Leidegren Before time... 1993 - - PowerPoint PPT Presentation

a programmable web framework
SMART_READER_LITE
LIVE PREVIEW

A Programmable Web Framework John Leidegren Before time... 1993 - - PowerPoint PPT Presentation

A Programmable Web Framework John Leidegren Before time... 1993 <HTML><BODY>...</HTML> Very static Server-side scripting IIS/ISAPI/ASP/VBScript/ASP.NET Apache/CGI/JSP PHP/PHP4+ ColdFusion? The Basic


slide-1
SLIDE 1

A Programmable Web Framework

John Leidegren

slide-2
SLIDE 2

Before time...

  • 1993
  • <HTML><BODY>...</HTML>
  • Very static
slide-3
SLIDE 3
  • IIS/ISAPI/ASP/VBScript/ASP.NET
  • Apache/CGI/JSP
  • PHP/PHP4+
  • ColdFusion?

Server-side scripting

slide-4
SLIDE 4

The Basic Idea

<% # server-side scripting and then some %> <html xmlns=”...”> <div id=”Name” runat=”server”>...</div> </html>

  • <% %> not well formatted XML
  • <? ?> processing instruction
  • runat=”server”
  • Not in the XHTML specification
  • Mixing view and code != MVC
slide-5
SLIDE 5

The Basic Idea

<% # server-side scripting and then some %> <html xmlns=”...”> <div id=”Name” runat=”server”>...</div> </html>

  • <% %> not well formatted XML
  • <? ?> processing instruction
  • runat=”server”
  • Not in the XHTML specification
  • Mixing view and code != MVC
slide-6
SLIDE 6

Worst Case

  • Copy-paste
  • No reusable master
  • No composability
  • No static type-checking
  • PHP
  • Runtime errors
slide-7
SLIDE 7

Trellis

A programmable web

slide-8
SLIDE 8

Trellis

  • Tightly integrated into Visual Studio 2008
  • A compiler framework
  • A web framework
  • A web server
  • Running on .NET 3.5 (Windows only)
slide-9
SLIDE 9

Trellis

  • Uses infix notation
  • Uses lambda calculus
  • Uses some lazy evaluation
  • Written entirely in C#
  • A fraction of the server is C++/CLI
  • A Haskell wannabe
slide-10
SLIDE 10

Trellis

Technology put to good use

slide-11
SLIDE 11

CodeMemberMethod
method
=
new
CodeMemberMethod(); method.Name
=
"Clone"; method.ReturnType
=
new
CodeTypeReference(
typeof(
Fragment
)
); method.Attributes
=
MemberAttributes.Public
|
MemberAttributes.Override; CodeObjectCreateExpression
objectCreation
=
new
CodeObjectCreateExpression();

  • bjectCreation.CreateType
=
new
CodeTypeReference(
someOtherType.Name
);
//
should
be
lazy

CodeMethodReturnStatement
returnStatement
=
new
CodeMethodReturnStatement(
objectCreation
); method.Statements.Add(
returnStatement
);

CodeDom Foofulishicness

slide-12
SLIDE 12

CodeLiteral
cloneLiteral
=
"Clone";
//
implicit
conversion CodeMemberMethod
cloneMethod
=
cloneLiteral .AsMethod<Fragment>() .SetAttributes(
MemberAttributes.Public
|
MemberAttributes.Override
) .AddStatement(
someOtherType.CreateInstance().Return()
);

Extension Methods

slide-13
SLIDE 13

byte[]
messageBody
=
...
//
array
of
bytes int[]
xs
=
messageBody .Select(
(
x,
i
)
=>
new
{
Value
=
x,
Index
=
i
}
)
//
zip .Where(
x
=>
x.Value
==
'='
) .Select(
x
=>
x.Index
)
//
project .ToArray();
//
lazy
until
evaluated

+ Lambda = LINQ

slide-14
SLIDE 14

Generator

IEnumerable<char>
GetRequestHeaderEnumerator() { int
k
=
0; while
(
k
!=
0x0d0a0d0a
)
//
<CR><LF><CR><LF> { k
=
(k
<<
8)
|
ReadByte(); yield
return
(char)(k
&
0x7f);
//
7‐bit
(ascii
clamp) } }

slide-15
SLIDE 15

//
C#
2.0 StringBuilder
x
=
new
StringBuilder();
 foreach
(
var
c
in
GetRequestHeaderEnumerator()
) { x.Append(
c
); } string
request
=
x.ToString(); //
C#
3.0 string
request
=
GetRequestHeaderEnumerator() .Aggregate(
new
StringBuilder(),
(
x,
c
)
=>
x.Append(
c
),
 x
=>
x.ToString()
);

slide-16
SLIDE 16

The Trellis Compiler

  • Standardized XML to reusable fragments
  • A fragment is reusable code
  • A fragment can be almost anything
  • A fragment is compiled into a .NET assembly
  • A Trellis application is just a .NET assembly
slide-17
SLIDE 17

Trellis

DEMO

slide-18
SLIDE 18

More work

  • Some things did not make the cut
  • Input validation
  • Dynamic compilation
  • Lean and mean coding style
  • Replace XML with NHaml
  • Provide NHaml language support in VS
slide-19
SLIDE 19

NHaml what is it?

Haml takes your gross, ugly templates and replaces them with veritable Haiku.

slide-20
SLIDE 20

NHaml

%one 

%two 



%three
Hey
there Compiles
to: <one> 

<two> 



<three>Hey
there</three> 

</two> </one>

slide-21
SLIDE 21

NHaml

%head 

%title
My
Sample
MVC
Application 

%link{
href="../../Content/Sites",
rel="stylesheet",
type="text/css"
} Compiles
to: <head> 

<title>My
Sample
MVC
Application</title> 

<link
href="../../Content/Site.css"
rel="stylesheet"
type="text/css"
/> </head>

slide-22
SLIDE 22

Problems

  • Static type-checking vs. dynamic content
  • Validation rules
  • Event handling
  • Separation of concerns
  • MVC
slide-23
SLIDE 23

Final Thoughts

  • I love to write code
  • The IDE is really part of the application

framework

  • Trellis is similar to The ASP.NET MVC

Framework

  • Putting new language technology to good

use is great fun!

slide-24
SLIDE 24
slide-25
SLIDE 25

The End

Questions?