Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Framework Development.pdf

Yehuda Katz
September 27, 2011
180

Framework Development.pdf

Yehuda Katz

September 27, 2011
Tweet

Transcript

  1. def hello(y) y += 1 sleep y puts y end

    x = 1 hello(x) puts "done"
  2. __script__ def hello(y) y += 1 sleep y puts y

    end x = 1 hello(x) puts "done" Name Value x
  3. __script__ Name Value x def hello(y) y += 1 sleep

    y puts y end x = 1 hello(x) puts "done"
  4. __script__ Name Value x 1 def hello(y) y += 1

    sleep y puts y end x = 1 hello(x) puts "done"
  5. hello __script__ Name Value y 1 def hello(y) y +=

    1 sleep y puts y end x = 1 hello(x) puts "done"
  6. hello __script__ Name Value y 2 def hello(y) y +=

    1 sleep y puts y end x = 1 hello(x) puts "done"
  7. hello __script__ Name Value y 2 def hello(y) y +=

    1 sleep y puts y end x = 1 hello(x) puts "done" Name Value x 1 "the stack"
  8. Scheduler "resume this in 2 seconds" hello __script__ Name Value

    y 2 def hello(y) y += 1 sleep y puts y end x = 1 hello(x) puts "done" Name Value x 1
  9. hello __script__ Name Value y 2 def hello(y) y +=

    1 sleep y puts y end x = 1 hello(x) puts "done"
  10. __script__ def hello(y) y += 1 sleep y puts y

    end x = 1 hello(x) puts "done" Name Value x 1
  11. def hello(y) y += 1 sleep y puts y end

    x = 1 hello(x) puts "done"
  12. __SCRIPT__ def read(file) File.read(file) end file = "README" body =

    read(file) puts body Name Value file "README" body
  13. read __SCRIPT__ def read(file) File.read(file) end file = "README" body

    = read(file) puts body Name Value file "README"
  14. read __SCRIPT__ def read(file) File.read(file) end file = "README" body

    = read(file) puts body Name Value file "README" Name Value file "README" body
  15. Scheduler "resume this when the file is ready to read"

    read __SCRIPT__ def read(file) File.read(file) end file = "README" body = read(file) puts body Name Value file "README" Name Value file "README" body
  16. Scheduler "resume this when the file is ready to read"

    read __SCRIPT__ def read(file) File.read(file) end file = "README" body = read(file) puts body Name Value file "README" Name Value file "README" body The File.read method takes care of returning the actual value once the thread resumes.
  17. read __SCRIPT__ def read(file) File.read(file) end file = "README" body

    = read(file) puts body Name Value file "README"
  18. __SCRIPT__ def read(file) File.read(file) end file = "README" body =

    read(file) puts body Name Value file "README" body <file text>
  19. def read(file) File.read(file) end d = "/Users" t1 = Thread.new

    do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__
  20. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main
  21. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ main t1
  22. Scheduler "resume this when you have a second" def read(file)

    File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t1 Name Value d "/Users"
  23. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ main t1 __SCRIPT__ t2
  24. Scheduler "resume this when you have a second" def read(file)

    File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t2 Name Value d "/Users"
  25. Scheduler def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t2 Name Value d "/Users" def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t1 Name Value d "/Users" __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main Name Value d "/Users" active thread inactive threads
  26. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ main t1 __SCRIPT__ t2
  27. Scheduler "resume this when t1 finishes" __SCRIPT__ def read(file) File.read(file)

    end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main Name Value d "/Users"
  28. Scheduler __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1

    = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main Name Value d "/Users" active thread inactive threads def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t1 Name Value d "/Users" def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t2 Name Value d "/Users"
  29. Scheduler def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t1 Name Value d "/Users" active thread inactive threads def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t2 Name Value d "/Users" __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main Name Value d "/Users"
  30. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ main t1 __SCRIPT__ t2
  31. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ main t1 __SCRIPT__ t2
  32. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ main t1 __SCRIPT__ t2
  33. Scheduler "resume this when the file is ready to read"

    def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ t1 Name Value d "/Users" Name Value file "/Users/ README"
  34. Scheduler active thread inactive threads def read(file) File.read(file) end d

    = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value __SCRIPT__ t2 Name Value d "/Users" __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main Name Value d "/Users" def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ t1 Name Value d "/Users" Name Value file "/Users/ README"
  35. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ main t1 __SCRIPT__ t2
  36. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ main t1 __SCRIPT__ t2
  37. __SCRIPT__ def read(file) File.read(file) end d = "/Users" t1 =

    Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ main t1 read __SCRIPT__ t2
  38. Scheduler "resume this when the file is ready to read"

    def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value body __SCRIPT__ t2 Name Value d "/Users" Name Value file "/Users/ README"
  39. Scheduler inactive threads __SCRIPT__ def read(file) File.read(file) end d =

    "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value main Name Value d "/Users" def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value body __SCRIPT__ t2 Name Value d "/Users" Name Value file "/Users/ README" def read(file) File.read(file) end d = "/Users" t1 = Thread.new do f = "#{d}/README" read(file) end t2 = Thread.new do f = "#{d}/.vimrc" read(file) end puts t1.value puts t2.value read __SCRIPT__ t1 Name Value d "/Users" Name Value file "/Users/ README" waiting for IO to be ready waiting for t1 to finish waiting for IO to be ready
  40. What's in That Stack State? Remember that the stack gives

    us debuggers, backtraces, and deferred return
  41. Upstream My Code App Development As an app developer, use

    the abstractions provided. Don't try to swap out parts of the stack 'for performance' or any other reason without UNDERSTANDING it.
  42. “ Mark Ramm Turbogears I’m hard on the Django folks

    here because I think the “tightly integrated/loosely coupled” buzz phrase is actually detrimental to understanding how the trade-off’s work. And there are trade-offs and those trade-offs mean that there isn’t and will never be one perfect web-framework which somehow magically isn’t subject to the down-side of any of the constraints and design trade-offs that we all have to deal with every day.
  43. What's the Escape Velocity? Complexity is pushed up the abstraction

    chain. Single systems shove it all into one place. Isolating concerns moves it to the links between the concerns. Too many isolated concerns at the same level of abstraction reintroduce complexity.
  44. Pick a Side, We're at War App Developer Framework Developer

    Upstream Pure Abstraction Participant Your Code You Live Here Learn from Similar Codebases Downstream N/A Package Abstractions and Interfaces