Fork me on GitHub
#cljdoc
<
2019-07-26
>
lread19:07:05

I have submitted a couple of PRs - if you are in a reviewing mood, feedback is MOST welcome.

lread21:07:44

I am starting a clj-kondo lint pass on cljdoc source. Fun fun fun!

lread21:07:41

clj-kondo warns about unused things, and I see quite often destructuring of keys that are not used, for example group-id and artifact-id are not used here: https://github.com/cljdoc/cljdoc/blob/d54cb58b20d2b4cb1e7c714b3637aa8b89956ce0/src/cljdoc/server/ingest.clj#L16

lread21:07:33

before I delete, was this some sort of strategy to help when walking through code with debugger or something? @martinklepsch

lread21:07:16

Thanks @borkdude, so it can be used to document the the incoming data structure… hmm…

borkdude21:07:51

at the cost of unnecessary destructuring.

borkdude21:07:27

you can also write (s/fdef ...) since there are already specs in cljdoc, it seems

lread21:07:45

and maybe confusion? Without clj-kondo I was assuming all destructured keys were used.

borkdude21:07:33

right. I'm leaning more towards 'only destructure what you need' these days

lread21:07:42

I think I am too. Like you say, if it needs more describing there are specs - although they can be far away from the function you are reading.

borkdude21:07:30

you can also put the expected keys in the docstring

borkdude21:07:51

but since there is a spec assert there anyway, you'll discover this soon enough

lread21:07:08

I thought this project announced today looked interesting: https://github.com/nedap/speced.def

lread21:07:42

anyway I shall wait for @martinklepsch to opine for cljdoc.

lread21:07:56

Yeah I suppose if they aren’t used they are really a comment, so docstring would be an alternative.

lread21:07:07

Anyway lots of fun to see what clj-kondo finds @borkdude!

borkdude21:07:58

I agree, it is fun 😉

lread22:07:48

actually @borkdude if the intent is documentation, although an underscore prefix might seem silly on a destructured key, it does convey the key is available but unused.

lread22:07:07

(ignoring performance cost)

borkdude22:07:43

but then you would be destructuring keys that aren't even there

lread22:07:53

ya but you aren’t using them anyway

lread22:07:03

so what’s the diff?

lread22:07:35

unless intent is also to see them when walking though with debugger…

borkdude22:07:43

some editors give you the arg names and destructuring info as you type. when you see underscores keys that's possibly confusing

borkdude22:07:19

when debugging things, you can destructure when you capture that map

lread22:07:43

ya… I don’t think intent is debugger support, just making wild guesses.

lread22:07:05

the convention of underscore = unused is wildly understood, I think people would understand… oh but editors might give confusing help… I see.

borkdude22:07:38

it's an interesting topic for cljdoc: destructuring as documentation, yes or no. I guess you will also see it in generated documentation?

lread22:07:04

i think so, lemme check…

borkdude22:07:50

so then the question is: is there a way to get this information without paying the penalty of destructuring? e.g providing an arg-list, or spec

lread22:07:16

or docstring

borkdude22:07:30

user=> (def ^{:arglists '([{:keys [:x :y :z]}])} f (fn [obj]))
#'user/f
user=> (doc f)
-------------------------
user/f
([{:keys [:x :y :z]}])
nil

borkdude22:07:43

codox might also pick up on that

martinklepsch22:07:41

cljdoc also looks at the arglists metadata

martinklepsch22:07:05

(And the code is largely based on codox)

martinklepsch22:07:49

I think specs would be a more complete/interesting data source than the destructuring and explicit declaration we can find in arglists metadata

martinklepsch22:07:10

Spec stuff really needs to be revisited. At some point I threw in the towel but maybe a different pair of eyes has different ideas

martinklepsch22:07:34

If there’s interest I would be happy to summarize my findings and some stuff that’s spread across GitHub comments

lread22:07:53

@martinklepsch I started asking about this when looking specifically at cljdoc codebase… then we got into our interesting general discussion. For cljdoc codebase, am I right that, for now, unused destructured keys act as documentation and should be left in?

borkdude22:07:05

(or move them to arglists if they aren't used, but you still want them in the outputted docs)

lread22:07:34

(right, good alternate option)

martinklepsch22:07:19

@lee I have explored using them this way but haven’t come to a strong opinion on either choice. Without an explicit decision (ADR) I’d suggest to not touch code solely for formatting* sake but if we need to make that decision we can totally just reformat everything 😂 *thats kind of how I view it I guess.

lread22:07:06

yeah for this topic, that makes sense to me.

lread22:07:42

unused namespaces are easy… they get deleted from code. unused destructured keys are a topic of their own.

martinklepsch22:07:43

If a linter doesn’t like this ~formatting that might be enough of a reason to make a change

lread22:07:59

well, the linter is just asking, “hey, are you sure you want to do this?” and we can answer, if we want, “thanks for the tip, we like things this way”

lread22:07:26

right now our answer for unused destructured keys is: we’re not sure, so thanks for the tip, but we’ll stick with what we are doing for now.

lread22:07:31

(I think)

lread22:07:33

or… we could try out @borkdude’s arglists metadata idea.

lread22:07:50

@martinklepsch, on the topic of formatting, I often forget to leave a space here or there in a commit, have you considered using a format checker to check for this type of thing? maybe cljfmt would work for this?

lread22:07:49

oh it is getting late for you guys… let’s chat another time.

borkdude22:07:44

it's finally cooling down here. we had a couple of days of 37-40 degrees Celsius and at night it wouldn't cool down below 24...

borkdude22:07:00

so I'm going to catch up some zzzs now

lread22:07:01

g’night

martinklepsch22:07:35

Good evening Lee! 👋