O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

My favorite slides

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Matlab plotting
Matlab plotting
Carregando em…3
×

Confira estes a seguir

1 de 11 Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (19)

Anúncio

Semelhante a My favorite slides (20)

Mais recentes (20)

Anúncio

My favorite slides

  1. 1. Some of my favorite slides for Online Working Group September 13, 2012
  2. 2. The Design Recipe The Design Recipe 1. Information Analysis and Data Design 2. Contract and Purpose Statement 3. Examples 4. Design Strategy 5. Function Definition 6. Tests common graphic elements emphasize unities (e.g. all "recipes" look like this)
  3. 3. Create 2 new arguments for the 2 differences. (define (foldr fcn val lon) (cond [(empty? lon) val] [else (fcn (first lon) (foldr fcn val (rest lon)))])) ;; strategy: higher-order function composition (define (sum lon) (foldr + 0 lon)) (define (product lon) (foldr * 1 lon)) We could call this "foldr" (don't ask why) This is predefined in ISL, so you don't need to write out this definition Colors show analogous elements boxes provide labels and commentary
  4. 4. World = Heli * Bombs * ..other stuff.. ----- world-after-tick : World -> World world-after-mouse-event : World Number Number MouseEvent -> World world-to-scene : World Scene -> Scene Heli = Posn * ..other stuff.. ----- heli-after-tick : Heli -> Heli heli-after-mouse-event : Heli Number Number MouseEvent -> Heli heli-to-scene : Heli Scene -> Scene Bombs = ListOf<Bomb> ----- bombs-after-tick : Bombs -> Bombs bombs-after-mouse-event : Bombs Number Number MouseEvent -> Bombs bombs-to-scene : Bombs Scene -> Scene Bomb = Posn * Radius ----- bomb-after-tick : Bomb -> Bomb bomb-after-mouse-event : Bomb Number Number MouseEvent -> Bomb bomb-to-scene : Bomb Scene -> Scene Observe Redundancies all functions for world have name world- and take World as first arg all functions for Heli have name heli- and take Heli as first arg all functions for Bomb have name bomb- and take Bomb as first arg all functions for Bombs have name bombs- and take Bombs as first arg but result types can be different layered introductions lead reader to draw conclusions
  5. 5. Ball% = (class* object% () (field x y radius selected?) (define/public (on-tick) ...) (define/public (on-mouse ...) ...) (define/public (add-to-scene s) ...) ...) FlashingBall% = (class* Ball% () (inherit-field x y radius selected?) (field time-left ...) (define/public (on-tick) ...) (define/public (on-mouse ...) ...) (define/override (add-to-scene s) (if (zero? time-left) ...) (place-image ... x y s)) ...) x = ... y = ... radius = ... selected = ... time-left = ... (define b1 (new FlashingBall% ...)) (send b1 add-to-scene s) (send b1 on-tick) (send b1 launch-missiles) b1 Every object knows its own methods motion paths show information or control flow
  6. 6. Circle% = (class* DraggableObj% (inherit-field x y) (define radius ...) (define/public (add-to-scene s) ...) (define/public (inside-this? mx my) ...) (define/public (would-hit-left-edge?) ...) ) DraggableObj% = (class* object% (field x y) (define/public (on-mouse mx my mev) ...(send this inside-this? mx my)...)) (define/public (on-tick) ...(send this would-hit-left-edge?)...) ) x = 20 y = 30 radius = 5 this = circle1 (send circle1 add-to-scene s) (send circle1 on-mouse mx my) (send this inside-this? mx my) Every object knows its own methods Here are a few of my favorite examples of motion paths
  7. 7. The Big Picture: Functional my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene define weight: define add-to-scene:
  8. 8. The Big Picture: Classes my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene my-circle-weight my-square-weight my-composite-weight my-circle-add-to-scene my-square-add-to-scene my-composite-add-to-scene class circle: class square: class composite:
  9. 9. (cond For a foo: [(foo? b) (min (foo-first-one b) (baz-mymin (foo-left b) n) (baz-mymin (foo-right b) n)) ] For a bar: [(bar? b) (min n (bar-lo b) (bar-hi b))])) 3. Change selectors to field references (cond For a foo: [(foo? b) (min first-one (baz-mymin left n) (baz-mymin right n)) ] For a bar: [(bar? b) (min n lo hi) Transitions illustrate transformations; ideally, the reader can go back and forth to see what happened
  10. 10. (cond For a foo: [(foo? b) (min first-one (baz-mymin left n) (baz-mymin right n)) ] For a bar: [(bar? b) (min n lo hi) (cond For a foo: [(foo? b) (min first-one (send left mymin n) (send right mymin n)) ] For a bar: [(bar? b) (min n lo hi) 4. Change function calls to method calls
  11. 11. (cond For a foo: [(foo? b) (min first-one (send left mymin n) (send right mymin n)) ] For a bar: [(bar? b) (min n lo hi) d In class foo% : (cond (define/public (mymin n) [(foo? b) (min first-one (send left mymin n) (send right mymin n))) d In class bar% : ] (define/public (mymin n) [(bar? b) (min n lo hi)) 5. Put method definitions into classes

×