SlideShare a Scribd company logo
INCREMENTAL DEVELOPMENT WITH LISP
       Building a Game and a Website




                                           @jlongster
                                       James Long
INCREMENTAL DEVELOPMENT

• “acyclic software development process developed in
 response to the weaknesses of the waterfall model”
 - Wikipedia

• Rapidly   evolving software by means of frequent small changes
CODING

• Let’s
      focus on PROGRAMMING, apply the same model to just
 the programmer

• Write   small pieces of code, run them, and repeat

• Tweak   and extend the program while it is running

• Advantages: instant   results, higher morale, less rabbit trails
WHY LISP?

• Lisp   is famous for embracing incremental development

• Very   expressive and dynamic

• Functional
           simplicity allows for “piece-by-piece” evaluation, or
 running small chunks of code quickly

• Thephilosophy of Lisp is built around incremental
 development
IN PRACTICE
• How    do you actually write code incrementally?

• REPL

• IDE

 • Emacs

   • SLIME

   • comint-mode
EXAMPLE #1
                                    VECTORS

• Goal: Write    a 3d vector library with support for addition

   (define-type v3
     x y z)

   EVAL

   (define (v3-add   v1 v2)
     (make-v3
      (+ (v3-x v1)   (v3-x v2))
      (+ (v3-y v1)   (v3-y v2))
      (+ (v3-z v1)   (v3-z v2))))

   EVAL




• Intimate   with what’s going on with the code
EXAMPLE #1
                                    VECTORS

• Goal: Write    a 3d vector library with support for addition
                                     (define-type v3
   (define-type v3                     constructor: really-make-vec3d
     x y z)                            x y z)
   EVAL                              EVAL
   (define (v3-add   v1 v2)          (define (make-v3 x y z #!key (scale 1.))
     (make-v3                          (really-make-vec3d (* x scale)
      (+ (v3-x v1)   (v3-x v2))                           (* y scale)
      (+ (v3-y v1)   (v3-y v2))                           (* z scale)))
      (+ (v3-z v1)   (v3-z v2))))
                                     EVAL
   EVAL
                                     v3-add is still available


• Intimate   with what’s going on with the code
EXAMPLE #2
                          RENDER QUEUE

• Goal: Write     a library which queues objects to render
    (define queue '())

    (define (queue-add obj)
      (set! queue (cons obj queue)))

    (define (queue-render-all)
      (for-each (lambda (obj)
                  (write obj))
                queue))

    EVAL-REGION


• Modify   a program while its running and never throw away
 state
EXAMPLE #2
                          RENDER QUEUE

• Goal: Write     a library which queues objects to render
    (define queue '())
                                       (define (queue-render-all)
    (define (queue-add obj)              (display "--- RENDERED OBJECTS ---n")
      (set! queue (cons obj queue)))     (for-each (lambda (obj)
                                                     (display obj)
    (define (queue-render-all)                       (newline))
      (for-each (lambda (obj)                      queue))
                  (write obj))
                queue))                queue and queue-add are the same as before

    EVAL-REGION


• Modify   a program while its running and never throw away
 state
INITIAL THOUGHTS?

• Emacs greatly enhances the ability for “live coding”, could be
 done in other editors though

• “Scratch   buffers” are commonly used to test the system

• Your “scratch   code” evolves into unit tests
REAL WORLD EXAMPLE #1
                            WEBSITE

• Clojure   is a Lisp dialect which runs on the JVM

• Compojure     is a web framework developed in Clojure

• jlongster.com

• Clojure
        supports SLIME, an incredible development
 environment fully embracing incremental development
REAL WORLD EXAMPLE #2
                           GAME

•Iused Gambit Scheme to make
 an iPhone game, Farmageddon

• Wrote  a tool that embeds
 “remote REPLs” in applications
 so that you can develop it
 SLIME-style

• Extended   Emacs keybindings
REAL WORLD EXAMPLE #2
                           GAME

•Iused Gambit Scheme to make
 an iPhone game, Farmageddon

• Wrote  a tool that embeds
 “remote REPLs” in applications
 so that you can develop it
 SLIME-style

• Extended   Emacs keybindings
PROBLEMS

• Youmust write your code in a way that allows incremental
 development

• Your   IDE must support it

• Sometimes    there’s a lot of overhead for little gain
WHAT ABOUT YOU?


• Most     of you don’t use Lisp, probably

• Python     and many other languages could support this too

• It’s   a different mindset that I challenge you to try
• Buymy game, available next week on the App Store for only
 $1.99

• @farmageddongame

• http://farmageddongame.com

More Related Content

Incremental Development with Lisp: Building a Game and a Website

  • 1. INCREMENTAL DEVELOPMENT WITH LISP Building a Game and a Website @jlongster James Long
  • 2. INCREMENTAL DEVELOPMENT • “acyclic software development process developed in response to the weaknesses of the waterfall model” - Wikipedia • Rapidly evolving software by means of frequent small changes
  • 3. CODING • Let’s focus on PROGRAMMING, apply the same model to just the programmer • Write small pieces of code, run them, and repeat • Tweak and extend the program while it is running • Advantages: instant results, higher morale, less rabbit trails
  • 4. WHY LISP? • Lisp is famous for embracing incremental development • Very expressive and dynamic • Functional simplicity allows for “piece-by-piece” evaluation, or running small chunks of code quickly • Thephilosophy of Lisp is built around incremental development
  • 5. IN PRACTICE • How do you actually write code incrementally? • REPL • IDE • Emacs • SLIME • comint-mode
  • 6. EXAMPLE #1 VECTORS • Goal: Write a 3d vector library with support for addition (define-type v3 x y z) EVAL (define (v3-add v1 v2) (make-v3 (+ (v3-x v1) (v3-x v2)) (+ (v3-y v1) (v3-y v2)) (+ (v3-z v1) (v3-z v2)))) EVAL • Intimate with what’s going on with the code
  • 7. EXAMPLE #1 VECTORS • Goal: Write a 3d vector library with support for addition (define-type v3 (define-type v3 constructor: really-make-vec3d x y z) x y z) EVAL EVAL (define (v3-add v1 v2) (define (make-v3 x y z #!key (scale 1.)) (make-v3 (really-make-vec3d (* x scale) (+ (v3-x v1) (v3-x v2)) (* y scale) (+ (v3-y v1) (v3-y v2)) (* z scale))) (+ (v3-z v1) (v3-z v2)))) EVAL EVAL v3-add is still available • Intimate with what’s going on with the code
  • 8. EXAMPLE #2 RENDER QUEUE • Goal: Write a library which queues objects to render (define queue '()) (define (queue-add obj) (set! queue (cons obj queue))) (define (queue-render-all) (for-each (lambda (obj) (write obj)) queue)) EVAL-REGION • Modify a program while its running and never throw away state
  • 9. EXAMPLE #2 RENDER QUEUE • Goal: Write a library which queues objects to render (define queue '()) (define (queue-render-all) (define (queue-add obj) (display "--- RENDERED OBJECTS ---n") (set! queue (cons obj queue))) (for-each (lambda (obj) (display obj) (define (queue-render-all) (newline)) (for-each (lambda (obj) queue)) (write obj)) queue)) queue and queue-add are the same as before EVAL-REGION • Modify a program while its running and never throw away state
  • 10. INITIAL THOUGHTS? • Emacs greatly enhances the ability for “live coding”, could be done in other editors though • “Scratch buffers” are commonly used to test the system • Your “scratch code” evolves into unit tests
  • 11. REAL WORLD EXAMPLE #1 WEBSITE • Clojure is a Lisp dialect which runs on the JVM • Compojure is a web framework developed in Clojure • jlongster.com • Clojure supports SLIME, an incredible development environment fully embracing incremental development
  • 12. REAL WORLD EXAMPLE #2 GAME •Iused Gambit Scheme to make an iPhone game, Farmageddon • Wrote a tool that embeds “remote REPLs” in applications so that you can develop it SLIME-style • Extended Emacs keybindings
  • 13. REAL WORLD EXAMPLE #2 GAME •Iused Gambit Scheme to make an iPhone game, Farmageddon • Wrote a tool that embeds “remote REPLs” in applications so that you can develop it SLIME-style • Extended Emacs keybindings
  • 14. PROBLEMS • Youmust write your code in a way that allows incremental development • Your IDE must support it • Sometimes there’s a lot of overhead for little gain
  • 15. WHAT ABOUT YOU? • Most of you don’t use Lisp, probably • Python and many other languages could support this too • It’s a different mindset that I challenge you to try
  • 16. • Buymy game, available next week on the App Store for only $1.99 • @farmageddongame • http://farmageddongame.com

Editor's Notes