Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Clojure Interactive Development 101 (myke.blog)
54 points by refset on Sept 1, 2024 | hide | past | favorite | 5 comments


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.


I like the simplicity of your implementation but I would fear overfitting to your example development data.

In clojure if youre writing tests, even a quick mock-up, I’d recommend you do so directly using “clojure.test”.

Clojure has my favorite test suite, especially when paired with “clojure.test.check”.

It’s super powerful, and fun to use with its toolbox of generators that can test over a broad variety of inputs.

When using the generators it’s less about the variables being defined so much as their properties.

https://clojure.org/guides/test_check_beginner


My original comment was only meant for real-time debugging, not for testing.


For sure, but you’re using test driven development just without writing the tests. (which I do think is a clever)

Might as well write the tests, or, as I recommended, generators for your expected input.


> 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!




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: