cljdoc

https://cljdoc.org/ & https://github.com/cljdoc/cljdoc
lread 2019-07-26T19:35:05.015700Z

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

lread 2019-07-26T19:35:29.015900Z

https://github.com/cljdoc/cljdoc/pull/331

lread 2019-07-26T19:35:49.016200Z

https://github.com/cljdoc/cljdoc/pull/334

lread 2019-07-26T19:50:10.016400Z

I did not fix the problem, but I did correct the spello :simple_smile: https://github.com/cljdoc/cljdoc/commit/d54cb58b20d2b4cb1e7c714b3637aa8b89956ce0

lread 2019-07-26T21:26:44.017100Z

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

lread 2019-07-26T21:31:41.018800Z

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

lread 2019-07-26T21:32:33.019900Z

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

borkdude 2019-07-26T21:33:44.020200Z

I recently commented on this here: https://github.com/candid82/joker/issues/240#issuecomment-508985091

lread 2019-07-26T21:39:16.022100Z

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

borkdude 2019-07-26T21:39:51.022800Z

at the cost of unnecessary destructuring.

borkdude 2019-07-26T21:40:27.023700Z

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

lread 2019-07-26T21:40:45.024200Z

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

borkdude 2019-07-26T21:41:33.024600Z

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

lread 2019-07-26T21:43:42.026100Z

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.

borkdude 2019-07-26T21:44:30.026800Z

you can also put the expected keys in the docstring

borkdude 2019-07-26T21:44:51.027400Z

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

lread 2019-07-26T21:45:08.027800Z

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

lread 2019-07-26T21:46:42.029200Z

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

lread 2019-07-26T21:47:56.029700Z

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

lread 2019-07-26T21:49:07.030200Z

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

borkdude 2019-07-26T21:55:58.031900Z

I agree, it is fun 😉

lread 2019-07-26T22:05:48.034200Z

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.

lread 2019-07-26T22:06:07.034500Z

(ignoring performance cost)

borkdude 2019-07-26T22:07:43.034900Z

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

lread 2019-07-26T22:07:53.035100Z

ya but you aren’t using them anyway

lread 2019-07-26T22:08:03.035300Z

so what’s the diff?

borkdude 2019-07-26T22:08:10.035500Z

right

lread 2019-07-26T22:08:35.036300Z

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

borkdude 2019-07-26T22:08:43.036600Z

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

borkdude 2019-07-26T22:09:19.037Z

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

lread 2019-07-26T22:09:43.037400Z

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

lread 2019-07-26T22:11:05.038700Z

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

borkdude 2019-07-26T22:11:38.039400Z

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

lread 2019-07-26T22:12:04.039600Z

i think so, lemme check…

borkdude 2019-07-26T22:14:50.040600Z

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

lread 2019-07-26T22:16:16.041Z

or docstring

borkdude 2019-07-26T22:18:30.041200Z

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

borkdude 2019-07-26T22:18:43.041500Z

codox might also pick up on that

martinklepsch 2019-07-26T22:19:41.042400Z

cljdoc also looks at the arglists metadata

martinklepsch 2019-07-26T22:20:05.043100Z

(And the code is largely based on codox)

martinklepsch 2019-07-26T22:21:49.045200Z

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

martinklepsch 2019-07-26T22:23:10.047Z

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

martinklepsch 2019-07-26T22:24:34.048600Z

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

borkdude 2019-07-26T22:24:53.049300Z

I added arglists to this discussion: https://github.com/candid82/joker/issues/240#issuecomment-515616779

lread 2019-07-26T22:25:53.050800Z

@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?

borkdude 2019-07-26T22:27:05.051700Z

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

lread 2019-07-26T22:27:34.052600Z

(right, good alternate option)

martinklepsch 2019-07-26T22:30:19.056100Z

@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.

lread 2019-07-26T22:31:06.056800Z

yeah for this topic, that makes sense to me.

lread 2019-07-26T22:31:42.058400Z

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

martinklepsch 2019-07-26T22:31:43.058500Z

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

lread 2019-07-26T22:32:59.060400Z

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”

lread 2019-07-26T22:34:26.061400Z

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.

lread 2019-07-26T22:34:31.061600Z

(I think)

lread 2019-07-26T22:37:33.064400Z

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

lread 2019-07-26T22:38:50.065400Z

@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?

lread 2019-07-26T22:39:49.066100Z

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

borkdude 2019-07-26T22:40:44.066800Z

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...

borkdude 2019-07-26T22:41:00.067100Z

so I'm going to catch up some zzzs now

lread 2019-07-26T22:42:01.067400Z

g’night

martinklepsch 2019-07-26T22:46:35.068800Z

Good evening Lee! 👋