Fork me on GitHub
#cursive
<
2023-12-14
>
JI Lao03:12:39

Hello everyone, I would like to ask what is the correct way to debug clojure code after downloading cursive. I used the method of debugging Java before, breakpoint debugging, and found many strange phenomena, such as a certain line of code that will always be executed in a loop. In addition, I use print in the do statement to print the log, but it is very troublesome and I cannot accurately debug the problem.

Alex Miller (Clojure team)03:12:45

you use it essentially the same in Clojure that you do in Java - start your repl or application in debug mode, set breakpoints, etc. because Clojure is much more concise, it's not uncommon to see several expressions on the same line if you are stepping (and/or some trickiness with where you hit breakpoints) - it's sometimes helpful to format your code around the area you care about to put expressions on different lines

3
JI Lao03:12:54

Thanks for the help, I'm going to try it now

onetom08:12:32

and if it's new code you are writing, then try to structure it in a way, that side-effecting parts of the code are separate from the purely functional parts. that way u can debug the purely functional parts by iterating over them using unit tests.

onetom08:12:09

eg. if u have some api response or db query result, then make a function which produces that result and a separate one which transforms it, so u can test the transforming function without the api or the database.

2
JI Lao08:12:35

Yes, I'm learning clojure through advent of code, it's all pure functions in there, it's just that I'm writing a lot of function logic in one function, and sometimes it's not the result I want, and I don't know how to troubleshoot it

JI Lao08:12:47

The method you provided to isolate the side effects is good, but not the debugging problem I'm currently experiencing, in time it's a pure function, and sometimes when it doesn't match the expected result, it's slow for me to troubleshoot via println

Tobias Gerdin12:12:58

Perhaps check out Flow Storm debugger, it looks more adapted to Clojure code

Daniel Slutsky09:12:18

@U06S1EJPL just made a self-contained demo about using https://scicloj.github.io/clay/ v2 from Cursive: https://www.youtube.com/watch?v=GsML75MtNXw It explains the main details about the Clay API and configuration and shows how one may publish a blog post using Clay. The API & config of Clay have simplified a lot thanks to Tim's wise ideas, and it is great to have this video explaining some of these ideas.

❤️ 1