Fork me on GitHub
#beginners
<
2023-05-19
>
Zach02:05:41

Currently using emacs+cider for clojure development. One thing I miss from python is being able to drop into a debugger when there is an error. Is there something similar for clojure? Would also love to hear any other tips on debugging since it's turning into the bottleneck for development 🙂

Zach04:05:46

I don't think this type of debugging exists atm. I checked https://calva.io/debugger/ too and no luck.

seancorfield04:05:02

I'll be honest, I haven't felt the need for a "debugger" in the classical sense -- in over a dozen years of working with Clojure in production. But with the REPL, especially being able to use it in remote processes, and tools like Portal (and Reveal and Morse/REBL), I find it pretty straightforward to debug problems...

👍 2
seancorfield04:05:50

...that said, I believe there are libraries that can open up a new REPL when an exception is raised and so you get full, interactive access to the error context (again, I've never felt the need for such things).

seancorfield04:05:30

I used to rely on classical debuggers a lot back when I did C++ and in the early days of working with Java (I switched to Java in '97).

Zach04:05:36

I'll check out those tools, thanks for sharing! It must be my code and workflow that needs to change. Curious, when your developing with clojure what do you find to be the biggest bottleneck in the development process?

seancorfield05:05:08

The development workflow with Clojure is unlike that of any other language and it takes a bit of getting used to.

seancorfield05:05:13

I don't really have any bottlenecks. I always have a REPL running. My apps run in my REPL. I use Portal to visualize data and display values from tap> calls that I add when I'm debugging a problem.

seancorfield05:05:40

I made this video several years ago showing what my workflow was like, for analyzing and fixing a bug in a library: https://www.youtube.com/watch?v=UFY2rd05W2g

🙌 2
seancorfield05:05:03

I've changed editors and workflow a fair bit since then but the essence is mostly the same.

seancorfield05:05:19

These days I use Calva/VS Code and generally have two Portal windows running inside the editor, but the core is still: always run a REPL, eval every change you make, use tap> liberally for debugging and tracing, use some sort of tap>-friendly tool for visualization.

jpmonettas11:05:58

@dingelsz3 take a look at https://github.com/jpmonettas/flow-storm-debugger a debugger for Clojure and ClojureScript that is IDE independent, show up in #flow-storm if you have any questions

👆 2
Zach λ03:05:56

@dingelsz3 evaluating forms is not cutting it?

seancorfield03:05:12

He said he uses Emacs, not VS Code.

Zach λ03:05:32

my mistake

seancorfield03:05:01

I linked him to the CIDER debugging stuff to see if that helps.

Zach λ03:05:20

good idea, totally missed the editor requirement

Zach04:05:08

Yeah I'd be open to using calva but I don't think it supports this either. What I'm looking for is the ability for the debugger to run whenever an exception is thrown without me having to find where to put the breakpoints

Zach04:05:35

btw, you've got a great name haha

2
Zach λ07:05:59

you too babe

jpmonettas11:05:33

> What I'm looking for is the ability for the debugger to run whenever an exception is thrown without me having to find where to put the breakpoints @dingelsz3 this is covered by #C03KZ3XT0CF

Uli06:05:20

If i want to do (last smth), should i prefer a list or a vector. I always struggle to remember, which is better for what. Does someone have a mnemonic for it? ;)

Ben Sless07:05:22

Last is always O(N), use a vector and peek if that matters. But why does it matter?

hifumi12307:05:14

The intuition I have for these kind of problems is “core functions operating on general sequences will always walk the sequence”. This is at least true of map, filter , reduce*, last, butlast, take, drop, and so on. Functions like pop and peek, on the other hand, depend on sequences satisfying specific protocols or have special treatment in the Clojure runtime. (In CLJS, it’s always a protocol; e.g. pop and peek is specifically for objects implementing IStack). * technically not true if you return reduced at any point in the reducing function, but that’s besides the point and if you understand this, chances are you already have some intuition for most core functions

Uli05:05:07

@UK0810AQ2 it only matters for my interest. I read that list and vectors behave different in terms of performance if you work on the end or on the top of the list. So doing a bit digging in different sources, I found a quite short but maybe helpful answer in stack overflow, which sorts out my "mind-confusion". My confusion comes from a misunderstanding: it's maybe not to interesting for accessing, but for adding / removing elements. Short cite: > [12:21] <Raynes> Vectors aren't seqs, right? > [12:21] <rhickey> Raynes: no, but they are sequential > [12:21] <rhickey> ,(sequential? [1 2 3]) > [12:21] <clojurebot> true > [12:22] <Raynes> When would you want to use a list over a vector? > [12:22] <rhickey> when generating code, when generating back-to-front > [12:23] <rhickey> not too often in Clojure https://stackoverflow.com/questions/1147975/in-clojure-when-should-i-use-a-vector-over-a-list-and-the-other-way-around

Uli05:05:14

so my takeaway for now is: use vectors. thanks @UK0810AQ2 and @U0479UCF48H