Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Dog Programming Language (UIST 2013)

The Dog Programming Language (UIST 2013)

Slides for UIST 2013 traversal @ CSIE, National Taiwan University

Johnson Liang

December 21, 2013
Tweet

More Decks by Johnson Liang

Other Decks in Programming

Transcript

  1. Salman Ahmad, Sepandar D. Kamvar MIT Media Lab, UIST 2013

    13年12⽉月29⽇日星期⽇日 MIT Media Lab, Long paper 這篇則是關於 Web programming 更直觀的去寫 server-client 程式
  2. (a) Pseudocode (b) Resource-Centric Code (Ruby + Sinatra) Allow a

    user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end UIST’13, October 8–11, 2013, St. Andrews, UK 13年12⽉月29⽇日星期⽇日 想要寫⼀一個功能, 讓使⽤用者能登⼊入,如果密碼不對,就多給三次機會 機會⽤用完之後把他們送到 “forget password”
  3. (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby

    + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do Web Applications 13年12⽉月29⽇日星期⽇日 寫成 Web application 就複雜很多 @這樣的思維叫 resource centric programing 邏輯切成 request 和 response,分給不同的 URL endpoint 去執⾏行 @ http 是 stateless 的,要記在 session 像「重試了幾次」 @還要記得刪掉
  4. (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby

    + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do Web Applications Resource-centric Programming - Request / Response 思維 - ⼀一件事分成很多 URL endpoints 13年12⽉月29⽇日星期⽇日 寫成 Web application 就複雜很多 @這樣的思維叫 resource centric programing 邏輯切成 request 和 response,分給不同的 URL endpoint 去執⾏行 @ http 是 stateless 的,要記在 session 像「重試了幾次」 @還要記得刪掉
  5. (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby

    + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do Web Applications Resource-centric Programming - Request / Response 思維 - ⼀一件事分成很多 URL endpoints Manual State Management - HTTP is stateless - ⼿手動記錄 cookie / session 13年12⽉月29⽇日星期⽇日 寫成 Web application 就複雜很多 @這樣的思維叫 resource centric programing 邏輯切成 request 和 response,分給不同的 URL endpoint 去執⾏行 @ http 是 stateless 的,要記在 session 像「重試了幾次」 @還要記得刪掉
  6. (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby

    + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do Web Applications Resource-centric Programming - Request / Response 思維 - ⼀一件事分成很多 URL endpoints Manual State Management - HTTP is stateless - ⼿手動記錄 cookie / session 13年12⽉月29⽇日星期⽇日 寫成 Web application 就複雜很多 @這樣的思維叫 resource centric programing 邏輯切成 request 和 response,分給不同的 URL endpoint 去執⾏行 @ http 是 stateless 的,要記在 session 像「重試了幾次」 @還要記得刪掉
  7. (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby

    + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 (c) Workflow-Centric Code (Dog) 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated Web Applications w/ Dog Workflow-centric Programming - 直覺的 control flow - 藏起 request / response Automatic State Management - 只需⽤用區域變數和迴圈 13年12⽉月29⽇日星期⽇日 改成⽤用 Dog 實作 看起來就和 pseudo code 像多了
  8. (a) Pseudocode (c) Workflow-Centric Code (Dog) (b) Resource-Centric Code (Ruby

    + Sinatra) Allow a user to try to login. If the password does not match, then give them 3 more chances before suggesting that they submit a 'Forgotten Password' request. 1 get "/login" do 2 session.delete("login_tries") 3 render "login_form.html" 4 end 5 6 post "/login" do 7 user = params["user"]; password = params["pass"] 8 if authenticate(user, password) then 9 session["user"] = user 10 session.delete("login_tries") 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 (c) Workflow-Centric Code (Dog) 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- plications are written as imperative control flows that directly user = STDIN.gets() password = STDIN.gets() 3.times do if User.find(user).password == password signin user show_dashboard_for user else puts "Wrong password. Try again." user = STDIN.gets() password = STDIN.gets() end end reset_password_for user Workflow-Centric 13年12⽉月29⽇日星期⽇日 和我們寫 command-line 時很類似 兩者都是 workflow 的思維 遇到 I/O 就 block,等使⽤用者的 input
  9. Workflow-Centric Prog. 13年12⽉月29⽇日星期⽇日 剛剛的例⼦子,感覺得到 Workflow Centric Programming 的不 同 @⼀一樣⽤用這份

    code 當例⼦子 介紹⼀一下 Dog 的重要關鍵字 @ input, output: show 把變數內容給使⽤用者看,listen 會開⼀一個通道,讓 client 傳資料回來
  10. Workflow-Centric Prog. (c) Workflow-Centric Code (Dog) 20 else 21 flash["message"]

    = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- 13年12⽉月29⽇日星期⽇日 剛剛的例⼦子,感覺得到 Workflow Centric Programming 的不 同 @⼀一樣⽤用這份 code 當例⼦子 介紹⼀一下 Dog 的重要關鍵字 @ input, output: show 把變數內容給使⽤用者看,listen 會開⼀一個通道,讓 client 傳資料回來
  11. Workflow-Centric Prog. ≡ show : 讓某變數能被 client 看到 ≡ listen:client

    傳資料回來的通道 (c) Workflow-Centric Code (Dog) 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- 13年12⽉月29⽇日星期⽇日 剛剛的例⼦子,感覺得到 Workflow Centric Programming 的不 同 @⼀一樣⽤用這份 code 當例⼦子 介紹⼀一下 Dog 的重要關鍵字 @ input, output: show 把變數內容給使⽤用者看,listen 會開⼀一個通道,讓 client 傳資料回來
  12. Workflow-Centric Prog. ≡ on:block & wait 通道內的資訊 ≡ 類似 CLI

    programming 的 readLine() (c) Workflow-Centric Code (Dog) 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- 13年12⽉月29⽇日星期⽇日 on: block 住執⾏行程序,等通道 login 裡⾯面有東⻄西進來再繼續 類似 command line interface 的 readline
  13. Workflow-Centric Prog. ≡ on each:註冊 callback,在資料抵達通道時 執⾏行。︒ (c) Workflow-Centric Code

    (Dog) 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. 13年12⽉月29⽇日星期⽇日 有些時候,⽤用 event handler 來寫會⽐比較直觀
  14. Server-Client Scripting 13年12⽉月29⽇日星期⽇日 另⼀一個特⾊色: server-client scripting @這裡的 server 是 @

    開發者寫⼀一些外觀樣板,加上 client library @client 會依照 server 執⾏行到哪,render 相對應 template
  15. Server-Client Scripting ≡ Server : dog 實作之 API server 13年12⽉月29⽇日星期⽇日

    另⼀一個特⾊色: server-client scripting @這裡的 server 是 @ 開發者寫⼀一些外觀樣板,加上 client library @client 會依照 server 執⾏行到哪,render 相對應 template
  16. Server-Client Scripting ≡ Server : dog 實作之 API server ≡

    Client : templates + JS / iOS / Android client lib 。︒ 13年12⽉月29⽇日星期⽇日 另⼀一個特⾊色: server-client scripting @這裡的 server 是 @ 開發者寫⼀一些外觀樣板,加上 client library @client 會依照 server 執⾏行到哪,render 相對應 template
  17. Server-Client Scripting ≡ Server : dog 實作之 API server ≡

    Client : templates + JS / iOS / Android client lib 。︒ ≡ Client 繪製 server 指定 template。︒ 13年12⽉月29⽇日星期⽇日 另⼀一個特⾊色: server-client scripting @這裡的 server 是 @ 開發者寫⼀一些外觀樣板,加上 client library @client 會依照 server 執⾏行到哪,render 相對應 template
  18. Server-Client Scripting - - , e - n o g

    y e - - - n - h - g s d y . - d g s Client Library 1 <script id="login" type="text/x-dog-template"> 2 <h3>Please Login</h3> 3 {{#listenForm listens.login}} 4 <input type="text" name="login"> 5 <input type="password" name="pass"> 6 <input type="submit" name="submit" value="Log In"> 7 {{/listenForm}} 8 </script> Dog API UI User input events are captured by client library JSON Request 1 2 3 4 5 6 UI The view that triggered the request is updated Templates Select template based on function name Templates Select template based on function name Templates Select template based on function name Render Template Render template based on displayed and listened data JSON Response { function_name:"login" displays: ... listens: ... } Figure 3. Dog’s client-side libraries are built around templates. Here, we show the Javascript client library. Developers create templates using Handlebars.js but other templating languages are supported as well. SERVER-CLIENT SCRIPTING With the rise of mobile OSes, developers are increasingly deploying native client applications on multiple platforms. UIST’13, October 8–11, 2013, St. Andrews, UK 13年12⽉月29⽇日星期⽇日 以 web client 為例 上⾯面是 template,把 display 的東⻄西和要 listen 的東⻄西放在 HTML 裡。 下⾯面有 javascript library 和 Dog server API 對接
  19. Server-Client Scripting action flow across multiple request- elopers rely on

    familiar state man- ocal variables, condition statements, State is implicitly captured by the d developers are afforded compila- sed debugging, well-defined function ways to write test cases. We refer to ng as workflow-centric programming amming is a natural and familiar way d allows developers to focus on the o create rather than low-level tech- many designers and programmers al- a prototyping tool to describe an ap- avior [14]. To confirm our intuition ogramming is a good fit for Web pro- mple study asking participants which ementations of a popular online ser- e implementation was written using gramming model and the other was rvice described in the study included Tumblr. Participants overwhelmingly centric model by a margin of 21 to 2. w programming is similar to console- Instead of calling print and d receive data from a terminal, Dog ilt-in show and listen commands to a Web-accessible API. The show e 11) makes a particular variable vis- e listen command (Figure 2c lines nel” that clients can use to send data ultiple channels and selectively wait t using the on block (Figure 2c line p when it reaches an on block and sent over the specified channel (just gram blocks on readLine until the Client Library 1 <script id="login" type="text/x-dog-template"> 2 <h3>Please Login</h3> 3 {{#listenForm listens.login}} 4 <input type="text" name="login"> 5 <input type="password" name="pass"> 6 <input type="submit" name="submit" value="Log In"> 7 {{/listenForm}} 8 </script> Dog API UI User input events are captured by client library JSON Request 1 2 3 4 5 6 UI The view that triggered the request is updated Templates Select template based on function name Templates Select template based on function name Templates Select template based on function name Render Template Render template based on displayed and listened data JSON Response { function_name:"login" displays: ... listens: ... } Figure 3. Dog’s client-side libraries are built around templates. Here, we show the Javascript client library. Developers create templates using Handlebars.js but other templating languages are supported as well. SERVER-CLIENT SCRIPTING With the rise of mobile OSes, developers are increasingly deploying native client applications on multiple platforms. While most of the client applications are often similar, they currently need to be reimplemented for each platform. With Dog, an application’s high-level logic is written server- side rather than client-side. Clients connect to the server and the server “tells” the client what they should do and when they should do it. Communication between the client and the server is done through a server-client scripting protocol that exposes what a program has shown and listened for. Dog’s model provides a clean separation between back-end business logic and front-end design. The client has complete UIST’13, October 8–11, 2013, St. Andrews, UK orkflow-Centric Code (Dog) end end end listen to everyone for logins on each login do user = person from login repeat 3 times if user: login.user has_password: login.pass then signin: login.user show_dashboard_for: user else message = "Wrong password. Try again." show message to user listen to user for logins on login do user = person from login end end end reset_password_for:user end 2. Server-side code to implement login logic. Workflow-centric mming allows for code to be written as a straightforward imper- ntrol flow. State is manage implicitly by the program’s execution amiliar techniques like control structures and local variables. In e-centric programming, state between individual server requests ually preserved by storing data in the session. tyle of server-side programming plays a specific and d role: it inspects incoming HTTP requests and pro- an HTTP response. Multistep logic that spans multiple ts needs to manually store state so that the relevant in- ion is available during a future request-response cycle 13年12⽉月29⽇日星期⽇日 和 server-side 的程式碼放在⼀一起看 可以看出執⾏行流程 @ server 開始的時候,server side 的 code 會先執⾏行⼀一次,註冊這⼀一堆 code 在 login channel 有東 ⻄西時執⾏行。 @⼀一開始,使⽤用者送出表單,client library 就會幫你把使⽤用者填的資料塞進 login 這個 channel。 @ server 拿到了 login 資料,就能執⾏行 callback,block 在等待新 login 資訊這裡 @ 此時, server 會把要 show 的 message, 想要 listen 的變數傳回給 clients,讓 client 找出對應的 template 顯⽰示。
  20. Server-Client Scripting action flow across multiple request- elopers rely on

    familiar state man- ocal variables, condition statements, State is implicitly captured by the d developers are afforded compila- sed debugging, well-defined function ways to write test cases. We refer to ng as workflow-centric programming amming is a natural and familiar way d allows developers to focus on the o create rather than low-level tech- many designers and programmers al- a prototyping tool to describe an ap- avior [14]. To confirm our intuition ogramming is a good fit for Web pro- mple study asking participants which ementations of a popular online ser- e implementation was written using gramming model and the other was rvice described in the study included Tumblr. Participants overwhelmingly centric model by a margin of 21 to 2. w programming is similar to console- Instead of calling print and d receive data from a terminal, Dog ilt-in show and listen commands to a Web-accessible API. The show e 11) makes a particular variable vis- e listen command (Figure 2c lines nel” that clients can use to send data ultiple channels and selectively wait t using the on block (Figure 2c line p when it reaches an on block and sent over the specified channel (just gram blocks on readLine until the Client Library 1 <script id="login" type="text/x-dog-template"> 2 <h3>Please Login</h3> 3 {{#listenForm listens.login}} 4 <input type="text" name="login"> 5 <input type="password" name="pass"> 6 <input type="submit" name="submit" value="Log In"> 7 {{/listenForm}} 8 </script> Dog API UI User input events are captured by client library JSON Request 1 2 3 4 5 6 UI The view that triggered the request is updated Templates Select template based on function name Templates Select template based on function name Templates Select template based on function name Render Template Render template based on displayed and listened data JSON Response { function_name:"login" displays: ... listens: ... } Figure 3. Dog’s client-side libraries are built around templates. Here, we show the Javascript client library. Developers create templates using Handlebars.js but other templating languages are supported as well. SERVER-CLIENT SCRIPTING With the rise of mobile OSes, developers are increasingly deploying native client applications on multiple platforms. While most of the client applications are often similar, they currently need to be reimplemented for each platform. With Dog, an application’s high-level logic is written server- side rather than client-side. Clients connect to the server and the server “tells” the client what they should do and when they should do it. Communication between the client and the server is done through a server-client scripting protocol that exposes what a program has shown and listened for. Dog’s model provides a clean separation between back-end business logic and front-end design. The client has complete UIST’13, October 8–11, 2013, St. Andrews, UK orkflow-Centric Code (Dog) end end end listen to everyone for logins on each login do user = person from login repeat 3 times if user: login.user has_password: login.pass then signin: login.user show_dashboard_for: user else message = "Wrong password. Try again." show message to user listen to user for logins on login do user = person from login end end end reset_password_for:user end 2. Server-side code to implement login logic. Workflow-centric mming allows for code to be written as a straightforward imper- ntrol flow. State is manage implicitly by the program’s execution amiliar techniques like control structures and local variables. In e-centric programming, state between individual server requests ually preserved by storing data in the session. tyle of server-side programming plays a specific and d role: it inspects incoming HTTP requests and pro- an HTTP response. Multistep logic that spans multiple ts needs to manually store state so that the relevant in- ion is available during a future request-response cycle 13年12⽉月29⽇日星期⽇日 和 server-side 的程式碼放在⼀一起看 可以看出執⾏行流程 @ server 開始的時候,server side 的 code 會先執⾏行⼀一次,註冊這⼀一堆 code 在 login channel 有東 ⻄西時執⾏行。 @⼀一開始,使⽤用者送出表單,client library 就會幫你把使⽤用者填的資料塞進 login 這個 channel。 @ server 拿到了 login 資料,就能執⾏行 callback,block 在等待新 login 資訊這裡 @ 此時, server 會把要 show 的 message, 想要 listen 的變數傳回給 clients,讓 client 找出對應的 template 顯⽰示。
  21. Server-Client Scripting action flow across multiple request- elopers rely on

    familiar state man- ocal variables, condition statements, State is implicitly captured by the d developers are afforded compila- sed debugging, well-defined function ways to write test cases. We refer to ng as workflow-centric programming amming is a natural and familiar way d allows developers to focus on the o create rather than low-level tech- many designers and programmers al- a prototyping tool to describe an ap- avior [14]. To confirm our intuition ogramming is a good fit for Web pro- mple study asking participants which ementations of a popular online ser- e implementation was written using gramming model and the other was rvice described in the study included Tumblr. Participants overwhelmingly centric model by a margin of 21 to 2. w programming is similar to console- Instead of calling print and d receive data from a terminal, Dog ilt-in show and listen commands to a Web-accessible API. The show e 11) makes a particular variable vis- e listen command (Figure 2c lines nel” that clients can use to send data ultiple channels and selectively wait t using the on block (Figure 2c line p when it reaches an on block and sent over the specified channel (just gram blocks on readLine until the Client Library 1 <script id="login" type="text/x-dog-template"> 2 <h3>Please Login</h3> 3 {{#listenForm listens.login}} 4 <input type="text" name="login"> 5 <input type="password" name="pass"> 6 <input type="submit" name="submit" value="Log In"> 7 {{/listenForm}} 8 </script> Dog API UI User input events are captured by client library JSON Request 1 2 3 4 5 6 UI The view that triggered the request is updated Templates Select template based on function name Templates Select template based on function name Templates Select template based on function name Render Template Render template based on displayed and listened data JSON Response { function_name:"login" displays: ... listens: ... } Figure 3. Dog’s client-side libraries are built around templates. Here, we show the Javascript client library. Developers create templates using Handlebars.js but other templating languages are supported as well. SERVER-CLIENT SCRIPTING With the rise of mobile OSes, developers are increasingly deploying native client applications on multiple platforms. While most of the client applications are often similar, they currently need to be reimplemented for each platform. With Dog, an application’s high-level logic is written server- side rather than client-side. Clients connect to the server and the server “tells” the client what they should do and when they should do it. Communication between the client and the server is done through a server-client scripting protocol that exposes what a program has shown and listened for. Dog’s model provides a clean separation between back-end business logic and front-end design. The client has complete UIST’13, October 8–11, 2013, St. Andrews, UK orkflow-Centric Code (Dog) end end end listen to everyone for logins on each login do user = person from login repeat 3 times if user: login.user has_password: login.pass then signin: login.user show_dashboard_for: user else message = "Wrong password. Try again." show message to user listen to user for logins on login do user = person from login end end end reset_password_for:user end 2. Server-side code to implement login logic. Workflow-centric mming allows for code to be written as a straightforward imper- ntrol flow. State is manage implicitly by the program’s execution amiliar techniques like control structures and local variables. In e-centric programming, state between individual server requests ually preserved by storing data in the session. tyle of server-side programming plays a specific and d role: it inspects incoming HTTP requests and pro- an HTTP response. Multistep logic that spans multiple ts needs to manually store state so that the relevant in- ion is available during a future request-response cycle submit form ! 13年12⽉月29⽇日星期⽇日 和 server-side 的程式碼放在⼀一起看 可以看出執⾏行流程 @ server 開始的時候,server side 的 code 會先執⾏行⼀一次,註冊這⼀一堆 code 在 login channel 有東 ⻄西時執⾏行。 @⼀一開始,使⽤用者送出表單,client library 就會幫你把使⽤用者填的資料塞進 login 這個 channel。 @ server 拿到了 login 資料,就能執⾏行 callback,block 在等待新 login 資訊這裡 @ 此時, server 會把要 show 的 message, 想要 listen 的變數傳回給 clients,讓 client 找出對應的 template 顯⽰示。
  22. Server-Client Scripting action flow across multiple request- elopers rely on

    familiar state man- ocal variables, condition statements, State is implicitly captured by the d developers are afforded compila- sed debugging, well-defined function ways to write test cases. We refer to ng as workflow-centric programming amming is a natural and familiar way d allows developers to focus on the o create rather than low-level tech- many designers and programmers al- a prototyping tool to describe an ap- avior [14]. To confirm our intuition ogramming is a good fit for Web pro- mple study asking participants which ementations of a popular online ser- e implementation was written using gramming model and the other was rvice described in the study included Tumblr. Participants overwhelmingly centric model by a margin of 21 to 2. w programming is similar to console- Instead of calling print and d receive data from a terminal, Dog ilt-in show and listen commands to a Web-accessible API. The show e 11) makes a particular variable vis- e listen command (Figure 2c lines nel” that clients can use to send data ultiple channels and selectively wait t using the on block (Figure 2c line p when it reaches an on block and sent over the specified channel (just gram blocks on readLine until the Client Library 1 <script id="login" type="text/x-dog-template"> 2 <h3>Please Login</h3> 3 {{#listenForm listens.login}} 4 <input type="text" name="login"> 5 <input type="password" name="pass"> 6 <input type="submit" name="submit" value="Log In"> 7 {{/listenForm}} 8 </script> Dog API UI User input events are captured by client library JSON Request 1 2 3 4 5 6 UI The view that triggered the request is updated Templates Select template based on function name Templates Select template based on function name Templates Select template based on function name Render Template Render template based on displayed and listened data JSON Response { function_name:"login" displays: ... listens: ... } Figure 3. Dog’s client-side libraries are built around templates. Here, we show the Javascript client library. Developers create templates using Handlebars.js but other templating languages are supported as well. SERVER-CLIENT SCRIPTING With the rise of mobile OSes, developers are increasingly deploying native client applications on multiple platforms. While most of the client applications are often similar, they currently need to be reimplemented for each platform. With Dog, an application’s high-level logic is written server- side rather than client-side. Clients connect to the server and the server “tells” the client what they should do and when they should do it. Communication between the client and the server is done through a server-client scripting protocol that exposes what a program has shown and listened for. Dog’s model provides a clean separation between back-end business logic and front-end design. The client has complete UIST’13, October 8–11, 2013, St. Andrews, UK orkflow-Centric Code (Dog) end end end listen to everyone for logins on each login do user = person from login repeat 3 times if user: login.user has_password: login.pass then signin: login.user show_dashboard_for: user else message = "Wrong password. Try again." show message to user listen to user for logins on login do user = person from login end end end reset_password_for:user end 2. Server-side code to implement login logic. Workflow-centric mming allows for code to be written as a straightforward imper- ntrol flow. State is manage implicitly by the program’s execution amiliar techniques like control structures and local variables. In e-centric programming, state between individual server requests ually preserved by storing data in the session. tyle of server-side programming plays a specific and d role: it inspects incoming HTTP requests and pro- an HTTP response. Multistep logic that spans multiple ts needs to manually store state so that the relevant in- ion is available during a future request-response cycle submit form ! 13年12⽉月29⽇日星期⽇日 和 server-side 的程式碼放在⼀一起看 可以看出執⾏行流程 @ server 開始的時候,server side 的 code 會先執⾏行⼀一次,註冊這⼀一堆 code 在 login channel 有東 ⻄西時執⾏行。 @⼀一開始,使⽤用者送出表單,client library 就會幫你把使⽤用者填的資料塞進 login 這個 channel。 @ server 拿到了 login 資料,就能執⾏行 callback,block 在等待新 login 資訊這裡 @ 此時, server 會把要 show 的 message, 想要 listen 的變數傳回給 clients,讓 client 找出對應的 template 顯⽰示。
  23. Server-Client Scripting action flow across multiple request- elopers rely on

    familiar state man- ocal variables, condition statements, State is implicitly captured by the d developers are afforded compila- sed debugging, well-defined function ways to write test cases. We refer to ng as workflow-centric programming amming is a natural and familiar way d allows developers to focus on the o create rather than low-level tech- many designers and programmers al- a prototyping tool to describe an ap- avior [14]. To confirm our intuition ogramming is a good fit for Web pro- mple study asking participants which ementations of a popular online ser- e implementation was written using gramming model and the other was rvice described in the study included Tumblr. Participants overwhelmingly centric model by a margin of 21 to 2. w programming is similar to console- Instead of calling print and d receive data from a terminal, Dog ilt-in show and listen commands to a Web-accessible API. The show e 11) makes a particular variable vis- e listen command (Figure 2c lines nel” that clients can use to send data ultiple channels and selectively wait t using the on block (Figure 2c line p when it reaches an on block and sent over the specified channel (just gram blocks on readLine until the Client Library 1 <script id="login" type="text/x-dog-template"> 2 <h3>Please Login</h3> 3 {{#listenForm listens.login}} 4 <input type="text" name="login"> 5 <input type="password" name="pass"> 6 <input type="submit" name="submit" value="Log In"> 7 {{/listenForm}} 8 </script> Dog API UI User input events are captured by client library JSON Request 1 2 3 4 5 6 UI The view that triggered the request is updated Templates Select template based on function name Templates Select template based on function name Templates Select template based on function name Render Template Render template based on displayed and listened data JSON Response { function_name:"login" displays: ... listens: ... } Figure 3. Dog’s client-side libraries are built around templates. Here, we show the Javascript client library. Developers create templates using Handlebars.js but other templating languages are supported as well. SERVER-CLIENT SCRIPTING With the rise of mobile OSes, developers are increasingly deploying native client applications on multiple platforms. While most of the client applications are often similar, they currently need to be reimplemented for each platform. With Dog, an application’s high-level logic is written server- side rather than client-side. Clients connect to the server and the server “tells” the client what they should do and when they should do it. Communication between the client and the server is done through a server-client scripting protocol that exposes what a program has shown and listened for. Dog’s model provides a clean separation between back-end business logic and front-end design. The client has complete UIST’13, October 8–11, 2013, St. Andrews, UK orkflow-Centric Code (Dog) end end end listen to everyone for logins on each login do user = person from login repeat 3 times if user: login.user has_password: login.pass then signin: login.user show_dashboard_for: user else message = "Wrong password. Try again." show message to user listen to user for logins on login do user = person from login end end end reset_password_for:user end 2. Server-side code to implement login logic. Workflow-centric mming allows for code to be written as a straightforward imper- ntrol flow. State is manage implicitly by the program’s execution amiliar techniques like control structures and local variables. In e-centric programming, state between individual server requests ually preserved by storing data in the session. tyle of server-side programming plays a specific and d role: it inspects incoming HTTP requests and pro- an HTTP response. Multistep logic that spans multiple ts needs to manually store state so that the relevant in- ion is available during a future request-response cycle submit form ! 13年12⽉月29⽇日星期⽇日 和 server-side 的程式碼放在⼀一起看 可以看出執⾏行流程 @ server 開始的時候,server side 的 code 會先執⾏行⼀一次,註冊這⼀一堆 code 在 login channel 有東 ⻄西時執⾏行。 @⼀一開始,使⽤用者送出表單,client library 就會幫你把使⽤用者填的資料塞進 login 這個 channel。 @ server 拿到了 login 資料,就能執⾏行 callback,block 在等待新 login 資訊這裡 @ 此時, server 會把要 show 的 message, 想要 listen 的變數傳回給 clients,讓 client 找出對應的 template 顯⽰示。
  24. Server-Client Scripting ≡ Client 不⽤用重新實作 Server 上的 high level interaction

    & navigation flow。︒ ≡ 跨 Web, Mobile 的⼀一致體驗 ≡ Separation of concern: back-end business logic v.s. front-end design 13年12⽉月29⽇日星期⽇日 Interaction 處理寫在 server 上 跨 web, mobile 的⼀一致體驗 做到 Separation of concern
  25. Key Contributions Thank you for listening! 13年12⽉月29⽇日星期⽇日 作者說 Dog 有兩個主要貢獻

    1. 屏蔽住 HTTP 的 statelessness,執⾏行環境⼜又能 scalable 2. Server side 邏輯能控制 client side 的互動
  26. Key Contributions ≡ Dog allows server-side code to be written

    as an imperative control flow that spans multiple requests and shields developers from HTTP’s statelessness while not sacrificing scalability. Thank you for listening! 13年12⽉月29⽇日星期⽇日 作者說 Dog 有兩個主要貢獻 1. 屏蔽住 HTTP 的 statelessness,執⾏行環境⼜又能 scalable 2. Server side 邏輯能控制 client side 的互動
  27. Key Contributions ≡ Dog allows server-side code to be written

    as an imperative control flow that spans multiple requests and shields developers from HTTP’s statelessness while not sacrificing scalability. ≡ Dog facilitates cross-client development by allowing server-side logic to control client-side interactions through a scripting protocol that minimizes code duplication while enabling developers to take advantage of platform- specific UI affordances. Thank you for listening! 13年12⽉月29⽇日星期⽇日 作者說 Dog 有兩個主要貢獻 1. 屏蔽住 HTTP 的 statelessness,執⾏行環境⼜又能 scalable 2. Server side 邏輯能控制 client side 的互動
  28. 中略 Paper 內有 詳細 syntax 介紹 & Sample apps 肪⻌Ⅷ櫢⯻

    13年12⽉月29⽇日星期⽇日 syntax 很像 smalltalk 值得⼀一提的是 把三種程式⽤用 Ruby, Dog, Python 各寫⼀一次,問 24 個⼈人說他們喜歡哪個 implementation 當然都是 dog 最⾼高。
  29. 中略 Paper 內有 詳細 syntax 介紹 & Sample apps 肪⻌Ⅷ櫢⯻

    + small user study 13年12⽉月29⽇日星期⽇日 syntax 很像 smalltalk 值得⼀一提的是 把三種程式⽤用 Ruby, Dog, Python 各寫⼀一次,問 24 個⼈人說他們喜歡哪個 implementation 當然都是 dog 最⾼高。
  30. Concurrency (c) Workflow-Centric Code (Dog) 21 flash["message"] = "Wrong password.

    Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple 13年12⽉月29⽇日星期⽇日
  31. Concurrency 的挑戰 ≡ 每個 user 都⼀一個 thread ≡ Memory 爆炸

    ≡ Ruby & Python 的 green thread 僅⽤用單核⼼心 軟體 (VM) 模擬 thread 13年12⽉月29⽇日星期⽇日
  32. Concurrency 的挑戰 ≡ 每個 user 都⼀一個 thread ≡ Memory 爆炸

    ≡ Ruby & Python 的 green thread 僅⽤用單核⼼心 ≡ Dog: “Task-based concurrency” ≡ ⼀一個 task ⼀一個 green thread ≡ 等 I/O 時可以存進硬碟 ≡ Immutable values & No shared references ≡ 不需 lock,可多核⼼心 軟體 (VM) 模擬 thread 13年12⽉月29⽇日星期⽇日
  33. Blocking Execution (c) Workflow-Centric Code (Dog) 21 flash["message"] = "Wrong

    password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple 13年12⽉月29⽇日星期⽇日
  34. Dog’s Solution to Blocking ≡ “Asynchronous Execution” / Promises ≡

    Certain function calls in Dog do not immediately return an output value but rather return a special future that promises to eventually hold the output. ≡ When a program attempts to access a future the current task will automatically block and the runtime will swap it out so another task can execute. 13年12⽉月29⽇日星期⽇日 ???
  35. Distributed Execution through on while -specific ake hun- ritten in

    ormance time en- res: complex impera- hreading runtime, cked by tely. m’s exe- iples be- er-Client syntax, se appli- ime and entation, nt c across specify ncoming h a URL th while ncluding ed rout- r object. tric pro- (c) Workflow-Centric Code (Dog) 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- plications are written as imperative control flows that directly allowing s through ion while m-specific ake hun- written in formance ntime en- ures: complex d impera- threading runtime, acked by itely. am’s exe- ciples be- ver-Client s syntax, rse appli- ntime and mentation, ent ic across s specify incoming th a URL ath while including ated rout- er object. ntric pro- (c) Workflow-Centric Code (Dog) 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- plications are written as imperative control flows that directly allowing ns through tion while m-specific take hun- written in rformance untime en- ures: s complex nd impera- threading e runtime, backed by nitely. ram’s exe- nciples be- ver-Client ’s syntax, erse appli- ntime and mentation, ment gic across rs specify incoming ith a URL path while (including cated rout- ler object. entric pro- (c) Workflow-Centric Code (Dog) 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- plications are written as imperative control flows that directly y allowing ons through ation while rm-specific t take hun- e written in erformance untime en- atures: ws complex nd impera- t threading he runtime, backed by finitely. gram’s exe- nciples be- rver-Client g’s syntax, verse appli- untime and ementation, ment ogic across ers specify n incoming with a URL path while (including cated rout- dler object. centric pro- (c) Workflow-Centric Code (Dog) 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- plications are written as imperative control flows that directly by allowing ons through cation while orm-specific at take hun- e written in performance runtime en- eatures: ws complex and impera- ht threading the runtime, e backed by efinitely. gram’s exe- rinciples be- erver-Client og’s syntax, verse appli- runtime and lementation, ement logic across pers specify an incoming with a URL m path while s (including ticated rout- ndler object. -centric pro- (c) Workflow-Centric Code (Dog) 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- by allowing tions through ication while form-specific hat take hun- be written in performance e runtime en- eatures: ows complex d and impera- ght threading y the runtime, re backed by definitely. ogram’s exe- principles be- Server-Client Dog’s syntax, diverse appli- g runtime and plementation, gement logic across opers specify an incoming c with a URL m path while ns (including sticated rout- andler object. e-centric pro- (c) Workflow-Centric Code (Dog) 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- by allowing ctions through plication while tform-specific that take hun- be written in g performance ue runtime en- features: lows complex d and impera- ight threading y the runtime, are backed by definitely. rogram’s exe- principles be- Server-Client Dog’s syntax, diverse appli- g runtime and mplementation, gement p logic across lopers specify o an incoming ic with a URL em path while ons (including isticated rout- handler object. ce-centric pro- (c) Workflow-Centric Code (Dog) 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management Instead of writing code as a series of URL endpoints, Dog ap- by allowing actions through plication while atform-specific that take hun- o be written in ng performance ue runtime en- e features: llows complex ed and impera- eight threading by the runtime, are backed by ndefinitely. program’s exe- e principles be- d Server-Client Dog’s syntax, l diverse appli- og runtime and mplementation, agement up logic across elopers specify to an incoming gic with a URL tem path while ions (including histicated rout- handler object. (c) Workflow-Centric Code (Dog) 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management nt by allowing ractions through uplication while latform-specific s that take hun- to be written in ng performance que runtime en- re features: allows complex red and impera- weight threading by the runtime, d are backed by indefinitely. program’s exe- re principles be- nd Server-Client f Dog’s syntax, al diverse appli- Dog runtime and implementation, nagement up logic across velopers specify to an incoming ogic with a URL stem path while tions (including phisticated rout- a handler object. (c) Workflow-Centric Code (Dog) 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management nt by allowing eractions through duplication while platform-specific ms that take hun- to be written in cing performance ique runtime en- ore features: allows complex ured and impera- weight threading d by the runtime, nd are backed by e indefinitely. a program’s exe- . ore principles be- and Server-Client of Dog’s syntax, ral diverse appli- Dog runtime and implementation, anagement k up logic across evelopers specify e to an incoming logic with a URL ystem path while ations (including ophisticated rout- a handler object. (c) Workflow-Centric Code (Dog) 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. Dog: Automatic State Management ile not sacrificing ent by allowing teractions through duplication while platform-specific ms that take hun- s to be written in ficing performance nique runtime en- core features: t allows complex tured and impera- tweight threading ed by the runtime, and are backed by se indefinitely. a program’s exe- s. core principles be- and Server-Client of Dog’s syntax, eral diverse appli- e Dog runtime and e implementation, anagement ak up logic across evelopers specify se to an incoming logic with a URL system path while cations (including ophisticated rout- (c) Workflow-Centric Code (Dog) 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. hile not sacrificing ment by allowing nteractions through e duplication while of platform-specific ams that take hun- es to be written in ficing performance unique runtime en- core features: at allows complex ctured and impera- htweight threading ged by the runtime, and are backed by use indefinitely. s a program’s exe- es. core principles be- g and Server-Client w of Dog’s syntax, veral diverse appli- he Dog runtime and ce implementation, G Management ak up logic across Developers specify nse to an incoming s logic with a URL system path while ications (including sophisticated rout- (c) Workflow-Centric Code (Dog) 11 redirect_to("/dashboard") 12 else 13 if session["login_tries"] == nil then 14 session["login_tries"] = 0 15 end 16 session["login_tries"] += 1 17 18 if session["login_tries"] >= 3 then 19 redirect_to("/forgot_password") 20 else 21 flash["message"] = "Wrong password. Please try again." 22 render "login_form.html" 23 end 24 end 25 end 26 1 listen to everyone for logins 2 3 on each login do 4 user = person from login 5 repeat 3 times 6 if user: login.user has_password: login.pass then 7 signin: login.user 8 show_dashboard_for: user 9 else 10 message = "Wrong password. Try again." 11 show message to user 12 listen to user for logins 13 on login do 14 user = person from login 15 end 16 end 17 end 18 reset_password_for:user 19 end Figure 2. Server-side code to implement login logic. Workflow-centric programming allows for code to be written as a straightforward imper- ative control flow. State is manage implicitly by the program’s execution using familiar techniques like control structures and local variables. In resource-centric programming, state between individual server requests is manually preserved by storing data in the session. This style of server-side programming plays a specific and limited role: it inspects incoming HTTP requests and pro- duces an HTTP response. Multistep logic that spans multiple requests needs to manually store state so that the relevant in- formation is available during a future request-response cycle (Figure 2b shows an example using sessions). This manual bookkeeping complicates many development tasks, for ex- ample, ensuring confirmation before changing a user’s email address, choosing a different billing method before making an online purchase, or viewing the next page from paginated results. 13年12⽉月29⽇日星期⽇日
  36. Distribution 的挑戰 ≡ Workflow programming ⽤用區域變數存 state ≡ 現存語⾔言只能放在單機的單⼀一 process

    ≡ Dog: “Dynamic Distributed Load Balancing” ≡ 每台機器的每個 CPU 都開⼀一個 scheduler ≡ Scheduler 都去 distributed task queue 拿 task ≡ ⼀一台機器可以繼續做壞掉機器上沒做完的 13年12⽉月29⽇日星期⽇日 ???
  37. 總結 ≡ Key Contribution ≡ Workflow-centric web framework ≡ 有⼈人做(Seaside,

    Tir) ≡ 但沒⼈人提過 scalability 13年12⽉月29⽇日星期⽇日 Seaside: smalltalk web framework, 2002 Tir: Lua + mongrel2 framework, 2011
  38. 總結 ≡ Key Contribution ≡ Workflow-centric web framework ≡ 有⼈人做(Seaside,

    Tir) ≡ 但沒⼈人提過 scalability ≡ Server-Client Scripting API ≡ 邏輯 on server︔;前端不只是 web pages 13年12⽉月29⽇日星期⽇日 Seaside: smalltalk web framework, 2002 Tir: Lua + mongrel2 framework, 2011