Title: How to Design and Generate Web Programs
1(No Transcript)
2(No Transcript)
3(No Transcript)
4(No Transcript)
5(No Transcript)
6(No Transcript)
7(No Transcript)
8(No Transcript)
9(No Transcript)
10(No Transcript)
11(No Transcript)
12(No Transcript)
13Programming theInteractive Web
- Shriram Krishnamurthi
- Brown University
14The Interactive Web
- The Web is increasingly dark matter
- Numerous Web APIs
- The Common Gateway Interface (CGI)
- Java Servlets
- Active Server Pages, Java Server Pages
- Scripting languages (Perl, PHP, etc)
- Microsofts Web Services
15Where You See This
- URLs become simple
- https//onepass.continental.com/asp/statement.asp
- URLs become complex
- http//maps.yahoo.com/py/ddResults.py?PytTmapta
rnametardescnewnamenewdescnewHashnewTHas
hnewStsnewTStstlttlnsltslnnewFLUse
AddressBelownewaddr3007SantaMonicaBoulevard
newcszsantamonica,canewcountryusnewTFLUseA
ddressBelownewtaddr2815SantaMonicaBoulevard
newtcszSantaMonica,CA904042409newtcountryus
SubmitGetDirections
16Why Dynamic Content?
- Server maintains large database
- Continuous upgrades (software and data)
- Platform independence for clients
- Sometimes, just a Web interface to an existing
program (eg, airline reservations)
17Red Herring Says
- No software? No problem. You should be moving
all your business processes onto the Web anyway.
(The Angler, Anthony B. Perkins, October 2002) - Discusses successful online subscription-based
service - No CD to install, no maintenance, no backup,
and no need to upgrade!
18The Orbitz Problem
- Not limited to punk script monkeys!
- Also found on Web sites of
- Microsoft
- Apple
- the National Science Foundation
19Programming InteractiveWeb Scripts
20Printing a Message(Console)
- print
- Hello, World\n
- exit
21Printing a Message(Web)
- print
- lthtmlgt
- ltheadgtlttitlegtTestlt/titlegt
- lt/headgt
- ltbodygt
- ltpgtHello, World!lt/pgt
- lt/bodygt
- lt/htmlgt
- exit
22Printing Uptime(Console)
- print
- Uptime s\n
- system (uptime)
- exit
23Printing Uptime(Web)
- print
- lthtmlgt
- ltheadgtlttitlegtUptimelt/titlegt
- lt/headgt
- ltbodygt
- ltpgtsystem (uptime)lt/pgt
- lt/bodygt
- lt/htmlgt
- exit
24Area of Circle(Console)
- r read Enter radius
- print
- area is d\n
- (3.14rr)
- exit
25Area of Circle(Web)
Enter radius
r get_binding radius
bindings ltpgtarea is (3.14rr)lt/pgt
26Adding Two Numbers(Console)
- n1 read Enter first
- n2 read Enter second
- print
- sum d\n
- (n1 n2)
- exit
27Two User Interfaces
Enter first
Enter second
Enter first
Enter second
28Interacting with Web Scripts
29Interacting with Web Scripts
30Interacting with Web Scripts
31Interacting with Web Scripts
32Interacting with Web Scripts
33Interacting with Web Scripts
34Adding Two Numbers(Web)
Enter first
n1 get_binding n1
bindings ltformgtlt/formgt
35A Central Problem
- Web scripts write a page, then terminate
- When the user replies, another script reads the
forms bindings and performs the next step
36Adding Two Numbers (Web)
Enter first
n1 get_binding n1
bindings ltformgtlt/formgt
Enter second
37Adding Two Numbers(Web)
Enter first
n1 get_binding n1
bindings ltformgtlt/formgt
n2 get_binding n2
bindings ltpgtsum (n1 n2)lt/pgt
Enter second
free variable
38In Practice
- System signals an error
- The user doesnt get a useful answer
- The user may not understand the error
- User expended a lot of effort and time
- Program captures variable by accident (i.e., it
implements dynamic scope!), or - internal server error
39Adding Two Numbers(Web)
Enter first
n1 get_binding n1
bindings ltformgtlt/formgt
n2 get_binding n2
bindings ltpgtsum (n1 n2)lt/pgt
Enter second
40Adding Two Numbers (Web)
Enter first
n1 get_binding n1
bindings ltformgtlt/formgt
n1 get_binding n1 bindings n2
get_binding n2 bindings ltpgtsum (n1
n2)lt/pgt
Enter second
n1
Enter second
41The Actual Form
- lthtmlgt
- ltheadgt
- lttitlegtThe Addition Pagelt/titlegt
- ltbodygt
- ltpgtEnter the second numberlt/pgt
- ltform method"get"
- action"http//www. .../cgi-second.ss"gt
- ltinput type"hidden" namen1" value1729"gt
- ltinput type"text" namen2" value"0"gt
- lt/formgt
- lt/htmlgt
42Problems
- Generating forms is a pain
- Programmer must manually track these hidden
fields - Mistakes can have painful consequences
- (Worst, silently induce dynamic scope)
43Bad News
44Whats in a URL?
- Lets go back to this URL
- http//maps.yahoo.com/py/ddResults.py?PytTmapta
rnametardescnewnamenewdescnewHashnewTHas
hnewStsnewTStstlttlnsltslnnewFLUse
AddressBelownewaddr3007SantaMonicaBoulevard
newcszsantamonica,canewcountryusnewTFLUseA
ddressBelownewtaddr2815SantaMonicaBoulevard
newtcszSantaMonica,CA904042409newtcountryus
SubmitGetDirections
45Whats in a URL?
- Lets go back to this URL
- http//maps.yahoo.com/py/ddResults.py?PytTmapta
rnametardescnewnamenewdescnewHashnewTHas
hnewStsnewTStstlttlnsltslnnewFLUse
AddressBelownewaddr3007SantaMonicaBoulevard
newcszsantamonica,canewcountryusnewTFLUseA
ddressBelownewtaddr2815SantaMonicaBoulevard
newtcszSantaMonica,CA904042409newtcountryus
SubmitGetDirections
46Breaking it Down
- Write it differently
- http//maps.yahoo.com/py/ddResults.py?
newaddr3007SantaMonicaBoulevard - newcszsantamonica,ca
- newcountryus
- newtaddr2815SantaMonicaBoulevard
- newtcszSantaMonica,CA904042409
- newtcountryus
- SubmitGetDirections
47Breaking it Down
- Or
- http//maps.yahoo.com/py/ddResults.py?
- newaddr 3007SantaMonicaBoulevard
- newcsz santamonica,ca
- newcountry us
- newtaddr 2815SantaMonicaBoulevard
- newtcsz SantaMonica,CA904042409
- newtcountry us
- Submit GetDirections
It looks an awful lot like a function call!
48The Real Picture
The script and the user are coroutines!
Event lines
script
user
49Control Flow Back Button
A silent action!
50Control Flow Cloning
script
user
51Control Flow Bookmarks
script
user
52What Programmers Need
- Multiply-resumable and restartable coroutines
- No language has exactly this the new control
operator for the Web - How do we implement it?
53How to Reengineer Programsfor the Web
54What we Want to Write
- n1 read
- Enter first
- n2 read
- Enter second
- print
- sum d\n
- (n1 n2)
- exit
55What we are Forced to Write1 of 3
- Main () print
- ltform actionf1gt
- Enter first
- ltinput namen1gt
- lt/formgt
56What we are Forced to Write2 of 3
- f1 (form) print
- ltform actionf2gt
- ltinput hidden namen1
- valueform.n1gt
- Enter second
- ltinput namen2gt
- lt/formgt
57What we are Forced to Write3 of 3
- f2 (form) print
- The sum is
- form.n1 form.n2
58Sensitive to Interaction
59Why Does this Work?
60Program Structure Destroyed
- n1 read
- Enter first
- n2 read
- Enter second
- print
- sum d\n
- (n1 n2)
- exit
- Main () print
- ltform actionf1gt
- Enter first
- ltinput namen1gt
- lt/formgt
- f1 (form) print
- ltform actionf2gt
- ltinput hidden namen1
- valueform.n1gt
- Enter second
- ltinput namen2gt
- lt/formgt
- f2 (form) print
- The sum is
- form.n1 form.n2
61The Reengineering Challenge
- Web interfaces have grown up
- from scripts to programs (or services)
- Need debugging, maintenance, evolution,
- We would like a Web compiler that
- Automatically splits programs by form
- Automatically propagates fields
- Preserves behavior in the face of bizarre control
flow