scittle

chromalchemy 2024-09-18T19:37:23.058639Z

I recently when successfully completed a debugging process with scittle! I had a significant amount of code bundled up in threading macros. Then painstakingly refactored it in into small (mostly pure) functions with precise intermediate names, so I could eval each function and it’s input state independently, and step through the data flow in the repl. Being able to use the nrepl integration was awesome, giving me the classic repl experience (in Calva), which in turn gave me I great boost of confidence to parse out some hairball code clojure-spin But I was wondering what the best practices for debugging are in scittle land. I’m sure it is a good process to write and compose a lot of small functions. But it is somewhat slow and tedious. I would like some tooling to instrument my code without necessarily having to break it all apart. If I was in cljs I would look toward things like debux, snitch, or FlowStorm. I Scittle I dont have those libraries on hand. I guess I could maybe compile one of those into the scittle inerpreter. But I want to go the other direction and port this code to Squint for performance on bundle size efficiency. So this question applies to Squint development too. How do you approach debuging in a more js way? Use any js libs or browser devtools? Just use log statements and dont worry about repl?

🏆 1
borkdude 2024-09-19T06:26:29.247569Z

Personally I never reach for any of the tools you mention for debugging. But you can use "dumb" techniques like prn, println, and inline defs, which I do all the time.

chromalchemy 2024-09-19T21:05:36.669819Z

Ok, good to know thats probably effective enough. I haven’t been using inline defs. Thats probably the missing piece.

jmglov 2024-09-22T10:59:51.227749Z

@chromalchemy Here’s what I use:

(defn log
  ([obj]
   (log nil obj {}))
  ([msg obj]
   (log msg obj {}))
  ([msg obj {:keys [log-atom] :as opts}]
   (when log-atom
     (swap! log-atom conj {:msg msg, :obj obj}))
   (if msg
     (js/console.log msg (clj->js obj))
     (js/console.log (clj->js obj)))
   obj))

(comment

  (log {:a 1})
  ;; => {:a 1}

  (log "Some map:" {:a 1})
  ;; => {:a 1}

  (def logs (atom []))
  ;; => #'soundcljoud/logs

  (log "Some map:" {:a 1} {:log-atom logs})
  ;; => {:a 1}

  @logs
  ;; => [{:msg "Some map:", :obj {:a 1}}]

  (log (js-obj :b 2 :c 3))
  ;; => #js {":b" 2, ":c" 3}

  )
The browser JS console looks like this:

👀 1