Fork me on GitHub
#off-topic
<
2021-04-26
>
phronmophobic18:04:26

What methods and tools do people use to explore medium size clojure data (small enough to fit in memory, large enough to be unwieldy for pprint)? Some options I can think of: • portal • REBL • reveal • graphviz • pprint • treemaps • foldable/collapsible trees

borkdude18:04:26

Usually I output to a .edn file and inspect it programmatically (with bb, jet or just in a JVM REPL)

phronmophobic18:04:59

@U04V15CAJ, are there any typical patterns you use when you programmatically inspect (eg. keys, vals, some other common functions)? I do use the repl to programmatically inspect, but it can be annoying when you try to look at a value and get a mountain of text.

borkdude18:04:32

I use keys a lot.

phronmophobic18:04:43

Part of the reason I'm asking is that I'm considering building better tools for this use case.

borkdude18:04:17

Note that there is also *print-length* and *print-level*

borkdude18:04:02

Although that doesn't prevent printing long strings :/

👆 2
phronmophobic18:04:47

and there are also some data shapes that circumvent those types of restrictions (eg. a 2d array of 10x10 elements)

borkdude18:04:28

(subs (str x) 0 10) ;)

borkdude18:04:36

(and then hope you don't get an NPE)

phronmophobic19:04:16

I have:

(defn truncate [s n]
  (subs s 0 (min (count s) n)))

borkdude19:04:32

yeah, but I'm usually too lazy to type that first ;)

phronmophobic19:04:24

As part of trying to upgrade my work flow and tooling, I have a project that exposes a dev namespace where I can put dev utlities. eg.

(require 'dev) 
(dev/truncate s 20)
And I have a :dev alias that adds the project to my classpath.

borkdude19:04:56

Isn't this what people use the 'user namespace for? I've never really used it as such though

borkdude19:04:18

oh but you add a lib, yeah, makes sense

phronmophobic19:04:02

yea, I guess I could have my dev project add the utilities to 'user. still experimenting.

borkdude19:04:46

You could be very evil and intern those vars into clojure.core which is how some tools achieve "injections"

borkdude19:04:51

so then they are available in every ns

borkdude19:04:21

it can be hard to forget about deleting them before deploying etc probably

borkdude19:04:49

although clj-kondo will warn you that its an unknown var

phronmophobic19:04:55

yea, I've thought about that. having a very short ns is also pretty close.

seancorfield19:04:34

A +1 for Reveal in general. pprint if I need it in logging.

hiredman20:04:23

I often just sit at the repl with (def x some-big-data) and build a big arrow expression

☝️ 2
hiredman20:04:40

(-> x :foo keys)

hiredman20:04:49

(-> x :foo :bar type)

hiredman20:04:59

(-> x :foo :bar first)

mauricio.szabo00:04:00

Most of the time I use "foldable / collapsible trees" that Chlorine already have

mauricio.szabo00:04:27

When the data is too complicated, I use reveal

mauricio.szabo00:04:35

And when it's too big, too nested, and I probably care a lot about a subset of fields, I use a "custom command with a specific renderer" on Chlorine, that's a feature that I'm aware is poorly documented 😢

Ben Sless06:04:02

I've been using Cider's inspector to great effect recently https://docs.cider.mx/cider/debugging/inspector.html

👍 3
phronmophobic06:04:15

wow, cider inspector is pretty great.

☝️ 3
borkdude09:04:20

oh I should try that!

Ben Sless10:04:48

It's one of those "I don't know how I lived without it until now" things

Ben Sless10:04:12

You can even inspect opaque reified objects and see all the values they close over