This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-08
Channels
- # announcements (1)
- # babashka (28)
- # beginners (30)
- # calva (1)
- # cider (13)
- # clojure (26)
- # clojure-brasil (2)
- # clojure-europe (29)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-spec (4)
- # clojure-uk (5)
- # cursive (17)
- # data-science (15)
- # datomic (8)
- # emacs (8)
- # events (1)
- # hyperfiddle (54)
- # joyride (18)
- # jvm (2)
- # kaocha (8)
- # lsp (8)
- # malli (4)
- # missionary (11)
- # reagent (5)
- # reitit (13)
- # releases (2)
- # rum (2)
- # scittle (6)
- # shadow-cljs (3)
Is there ROI on switching to a 'real' clojure debugger (and which would you recommend), I have a very ingrained habit of 'debugging my code via REPL + adding inline defs temporarily and never seem to knock the habit, even though i tell myself i'll find a better way. The REPL works pretty well.., just need a nudge if its worth it.
I use a debugger quite rarely, but the ROI is worth it. Sometimes you just need to be able to step through the program's execution, look at local variables, dig into nasty data. Maybe you have a weird bug inside a go block and only FlowStorm can help. Then the ROI is infinite. If you're an Emacs user the debugger + inspector offer a very tight and well integrated experience. Give it a shot
I'll just counter and say that in 13+ years of using Clojure, I've never felt the need to reach for more than REPL + println
(although now I use REPL + tap>
+ Portal).
@UK0810AQ2 i'm an emacs user, between cider, flowstorm, and inspector, any preferences, or they're all useful for different reasons
I admit, I've never tried FlowStorm...
But I never really liked step debugging even back when I used languages where it really was the only option š
at least you've tried something š i've just done the same thing I was doing since day 1 of clojure, nothings changed in this regard in several years.
tap>
changed my (debugging) life š
Working on Clojure itself, I am almost always in a mix of Java and Clojure, and the IntelliJ debugger is a big boost for me. But when Iām using only Clojure, I rarely bother with a debugger.
Given you mention cider, a new approach is to use cider-log-mode, which is integrated with the cider Inspector.
My workflow in real world projects goes as follow:
ā¢ Log stuff with a context (Logback MDC context, timbre/with-context+
) in strategic places (middleware. http clients, sql queries, some hand-picked places)
ā¢ See the logged stuff right into emacs
ā¢ When needed, hit RET
into a line, then the context will pop up into the Inspector
I find it cool as it bridges old-style logging with application-wide data tracing which is similar to flowstorm, but less exhaustive (which can feel more focused - I only follow data in the places where I think it's worthwhile)
If you're an Emacs user, just give cider's debugger a shot, it's awesome and at the tip of your fingers. That's 99.9% of my debugging needs
I tap> Clojure evaluation and mlog log events to portal automatically, which gives me all I need (also works with any repl connected editor) When I was learning I did find Cider debug tool useful when I messaged up a larger loop recur expression, or similar iterative expression, e.g. https://practical.li/spacemacs/debug-clojure/cider-debug/ Although now I still mostly use the repl and break down the loop recur (if I didn't write it)
I use either snitch (https://github.com/AbhinavOmprakash/snitch) or cider debugger if I need more than inline defs, which I rarely do.
Pretty sure clojure.pprint/pprint
doesn't do that by itself.
You can try overriding (defmethod print-method String ...)
with your own impl that does that, but it'll affect other printing as well.
I would try a different library first. Perhaps zprint
can do that, it has an insane amount of options.
thanks I could instead post-process the result: splitlines any trailing strings over widthmax get "" -> "" "" treatment with matching indent below, so still valid /equiv EDN? doesn't handle preusmably the same problem with integers/keywords but if you can handle trailing strings it's more than an 80-20 probably?
Hey all I have a question regarding https://github.com/clojure/core.cache, what is the best practice regarding where to create the cache, is it 1. Per namespace where it is used 2. In a namespace and then referred when needed
That's exactly the same question as where to create a non-public function. Just use the same reasoning you'd use there.
Depending on your development approach, storing the cache in the same ns where it's used under a plain def
and not defonce
might make things easier when you reload the whole namespace.
Is there any way to get the printer to output qualified keywords using the ::foo
syntax instead of :some.overly.verbose.namespace/foo
?
Just looking for a way to improve readablility of these forms at the REPL, much the same function as they serve in a source file by reducing visual clutter.
Note that this affects all printing calls happening in that REPL session:
user=> (import '( Writer))
java.io.Writer
user=> (defmethod print-method clojure.lang.Keyword [o ^Writer w] (.write w (if (= (name (ns-name *ns*)) (namespace o)) (str "::" (name o)) (str o))))
#object[clojure.lang.MultiFn 0x1ee29c84 "clojure.lang.MultiFn@1ee29c84"]
user=> :dev/a
:dev/a
user=> (ns dev)
nil
dev=> :dev/a
::a
A more robust option that doesn't affect other print calls is to run your own REPL via an explicit call to clojure.main/repl
with the right :print
option.
If you're using nREPL, there's probably an existing middleware that does it, or you can make one yourself.