Clojure Interactive Development 101

  • I'd love to use all this but the fact that you have to substitute in variables just makes this very not-useful.

    Ideally in functional programming everything is a (pure) function (and this is how I program), so you never have your variables defined.

    Instead, my standard setup is to debug a function by saving its arguments in a vector, e.g.

      (defn buggy-function [a b c]
       (def test-bf [a b c]) ;; <- add this
       ... function body ...
      )
    
    Then I can call buggy-function with

      (apply buggy-function test-bf)
    
    and modify the code until it behaves as expected.

    This is also where immutability has its grand appearance.

  • > Note that def we have inserted, to define a global variable request. This is a powerful debug mechanism, but a better way to use it is a tool like [snitch](https://github.com/AbhinavOmprakash/snitch).

    Wow, wish I knew about snitch earlier! I have been using a similar, much less powerful, set of macros for this: https://gist.github.com/mjdiloreto/9e7c65023fff691b5ab7d297d...

    In my experience, this is a phenomenal way to develop. You just replace whatever `defn` or `let` you are working on with `defn` and `let`, and interact with your app normally (click around in the UI, trigger the frontend or backend functions you are examining). Combined with a tool like portal (https://github.com/djblue/portal) you can quickly get an overview of your system while it is running!