clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
borkdude 2020-03-26T16:23:56.026Z

The CLJS compiler emits arity warnings at compile time. Any chance Clojure JVM could get this one day?

2020-03-26T16:39:37.027Z

I’ve found it ironic before that CLJS does the arity warning - with an underlying platform (JS) that doesn’t care about arity really; while CLJ doesn’t - with and underlying platform (JVM) that does definitely care

2020-03-26T16:40:06.027600Z

of course, it’s really probably just a result of the compiler impl though

dominicm 2020-03-26T16:53:14.029300Z

The difference is that if you've run your clojurescript code, it may not work as you expect. The clojure code won't run at all though. It's really an attempt to make clojurescript more like clojure.

✅ 1
ghadi 2020-03-26T16:58:33.030500Z

Who has a community-accepted reaction gif for "premature solution space conversation"?

😂 1
alexmiller 2020-03-26T17:00:27.031Z

:rich:

ghadi 2020-03-26T17:00:33.031200Z

yeah that works

dominicm 2020-03-26T17:02:25.033200Z

You'll gain a reputation if you repeat that enough

alexmiller 2020-03-26T17:04:17.034Z

you hear something every morning for several years and it starts to sink in :)

dominicm 2020-03-26T17:05:53.035100Z

Does Rich beat you guys with this stick a lot? :) (in a good way of course)

alexmiller 2020-03-26T17:07:43.035800Z

you make it sound bad

ghadi 2020-03-26T17:08:23.036400Z

heh

ghadi 2020-03-26T17:08:31.036700Z

seriously, arity checking is overrated

ghadi 2020-03-26T17:09:02.037400Z

i get the appeal, but the economics don't make sense to me

ghadi 2020-03-26T17:09:29.038Z

something like spec/instrument could give you nested arity checking on every input argument

ghadi 2020-03-26T17:09:50.038500Z

(nested meaning you pass in some larger shape, and the whole thing is checked)

ghadi 2020-03-26T17:10:11.038900Z

arity is but one dimension

borkdude 2020-03-26T17:17:41.040300Z

premature? this feature should have landed 10 years ago 😉

borkdude 2020-03-26T17:18:36.040900Z

I mean, hotfixing in the REPL is cool (https://twitter.com/borkdude/status/1243211177703997441) but this problem wouldn't have happened if I had ran my own linter or if Clojure emitted some basic warnings 😉

borkdude 2020-03-26T17:20:28.041500Z

I'd rather have one basic piece of feedback than pages full of spec output in many situations

alexmiller 2020-03-26T17:22:15.042Z

spec does not produce pages of output so that's a strawman

borkdude 2020-03-26T17:22:43.042500Z

it depends. I had spec produce pages of output earlier today.

alexmiller 2020-03-26T17:24:05.043300Z

in what context?

borkdude 2020-03-26T17:24:16.043500Z

also spec is optional. many functions will be unspec'ed. the compiler can already infer something is not going to work. emitting a warning seems the sane thing to do.

👍 1
borkdude 2020-03-26T17:24:35.044Z

the pages full happend with a spec that we have on our component system

borkdude 2020-03-26T17:24:45.044300Z

unrelated to the arity error btw

ghadi 2020-03-26T17:26:21.045200Z

this is a really unfocused complaint. I'm lost between arity checking and what this stuff is about spec output

borkdude 2020-03-26T17:26:49.045600Z

well, you brought up spec as an alternative, that is why.

2020-03-26T17:27:10.046200Z

seems like the arity argument was made quite clear

2020-03-26T17:27:52.047500Z

I get that clj compiler isn’t likely going to rapidly change this

2020-03-26T17:28:06.048300Z

but think the conversation seems really dismissive here

alexmiller 2020-03-26T17:28:39.049600Z

I'm not being dismissive

ghadi 2020-03-26T17:28:41.049700Z

I'm just saying there are degrees of what gets checked, different choices about when things get checked, and there need to be serious evaluations of things

ghadi 2020-03-26T17:28:50.050Z

not leading with solutions

ghadi 2020-03-26T17:29:28.051100Z

cost/benefit analyses

alexmiller 2020-03-26T17:29:32.051500Z

I think it's a reasonable thing to want, I just don't know the complexity of effort/feasibility vs the gain vs the priority of everything else we have in the queue

👍 1
borkdude 2020-03-26T17:30:00.052200Z

I understand that too.

alexmiller 2020-03-26T17:30:33.053700Z

clojurescript is doing whole program analysis, doesn't that make it more feasible to know if the arity is "right" vs clojure where functions can be rebound to have different arities?

borkdude 2020-03-26T17:31:03.054800Z

good point

alexmiller 2020-03-26T17:31:30.056700Z

I've never talked about this with Rich

borkdude 2020-03-26T17:31:35.057Z

it's not very common to rebind functions to different arities maybe?

2020-03-26T17:31:39.057300Z

yeah, perhaps that clears up the “irony” comment I made before, among other things

seancorfield 2020-03-26T17:31:48.057800Z

I'll argue against a compiler error for that since it would mean you couldn't eval code when you had arity errors in a path that you are not trying to invoke -- it would potentially make RDD harder because work-in-progress code might become uncompilable.

1
2020-03-26T17:31:56.058200Z

I was surprised to see arity warnings in CLJS really (coming from doing CLJ only for a long while)

ghadi 2020-03-26T17:31:57.058300Z

I think tools like clj-kondo, eastwood, fill a real gap. If I were to present Alex with a proposal to "add arity checking to the compiler", he would tell me to go back to the drawing board and get a problem statement

👍 1
borkdude 2020-03-26T17:32:15.058800Z

@seancorfield in CLJS this isn't an error, it's just a warning message from the compiler. Compare to e.g. warn on reflection.

alexmiller 2020-03-26T17:32:32.059400Z

well that seems reasonable

2020-03-26T17:32:43.060100Z

also, in CLJS isn’t it the case that it doesn’t check anonymous fn’s?

seancorfield 2020-03-26T17:32:58.060900Z

Ah, sorry, I thought you were arguing for a compiler error. Yeah, a warning wouldn't really bother me too much.

➕ 1
alexmiller 2020-03-26T17:33:21.061500Z

this is not really on my radar - I do not see a high quantity of complaints specifically about this, but maybe they are just a subset of "errors are bad" that has not been well analyzed

borkdude 2020-03-26T17:34:10.062300Z

ok

borkdude 2020-03-26T17:34:42.063300Z

btw I'm not really complaining, I just find it a useful thing from CLJS, but you could be right in that CLJS has more information at compile time

alexmiller 2020-03-26T17:34:49.063400Z

I'm not saying I'm right necessarily, maybe I'm just missing that

2020-03-26T17:35:02.063800Z

clj-kondo should just check this for us - the answer is now clear

alexmiller 2020-03-26T17:35:46.065Z

I appreciate having clj-kondo to help with stuff like this during dev :)

ghadi 2020-03-26T17:35:58.065200Z

me too

ghadi 2020-03-26T17:36:30.066100Z

@borkdude @mikerod I hope I didn't seem dismissive

alexmiller 2020-03-26T17:36:47.067Z

just in general, clj function objects are intentionally (to my eye) absent of signature information

borkdude 2020-03-26T17:37:14.068100Z

ok, I'll run clj-kondo next time before I push to production 😛

ghadi 2020-03-26T17:37:31.068700Z

I always get in trouble for leading with a solution rather than a problem, and when I approach something from the problem side, way better/more comprehensive/satisfying solutions emerge

1
alexmiller 2020-03-26T17:37:51.069300Z

IFn doesn't tell you anything about arities

2020-03-26T17:38:37.070400Z

@ghadi (on my end) I think you clarified it all and I appreciated your explanation. I probably just misread the tone originally.

1
2020-03-26T17:38:52.071100Z

Arities end up seeming more complicated than I originally even considered too.

alexmiller 2020-03-26T17:39:01.071700Z

I have not ever talked about this specifically with Rich, but in general he favors things that leave options open

alexmiller 2020-03-26T17:39:34.072800Z

by requiring less here, you allow your code to work as things expand in the future

alexmiller 2020-03-26T17:40:05.073100Z

that's a very Rich way to think about things

🙌 1
borkdude 2020-03-26T17:41:16.074900Z

what does an arity warning have to do with requiring less?

alexmiller 2020-03-26T17:41:36.075400Z

sorry, I'm probably not being clear

borkdude 2020-03-26T17:41:54.076Z

do you mean metadata on IFn about arities?

alexmiller 2020-03-26T17:42:11.076500Z

yeah, functions don't require anything saying what's allowed

alexmiller 2020-03-26T17:42:26.076900Z

so that widens the possibility of things that can be invokable

borkdude 2020-03-26T17:42:45.077500Z

giving information is something distinct from saying/checking what is allowed imo

alexmiller 2020-03-26T17:43:13.078Z

well how do you check without the info?

alexmiller 2020-03-26T17:43:50.079100Z

you're trying to do a check from the call side

alexmiller 2020-03-26T17:44:19.079900Z

you could check when invoking a var what the current known arities are and emit a warning. there's a cost to that check of course, but you'd probably happily pay that at the REPL for the warnings (or at "build" time)

borkdude 2020-03-26T17:44:35.080300Z

yeah, I mean, providing information on IFn is something else than IFn saying: you're not allowed to call me, I will throw.

borkdude 2020-03-26T17:44:57.080900Z

the compiler information processing is something that doesn't have to interfere with the execution

borkdude 2020-03-26T17:46:15.081400Z

a bit like the check you made in core.async: it's not going to alter existing programs, it just emits a bit of feedback

alexmiller 2020-03-26T17:46:55.082Z

the majority of the time I spent working on that was trying not to affect the performance for programs not doing the check

ghadi 2020-03-26T17:47:13.082100Z

And arity mismatch is only one dimension of "called it wrong"

ghadi 2020-03-26T17:47:49.083100Z

highly likely to catch an arity mismatch before it leaves your laptop

borkdude 2020-03-26T17:47:52.083300Z

I guess CLJS works differently enough that it makes sense there, since you typically only compile prior to deployment

borkdude 2020-03-26T17:48:28.083900Z

I mean, on the JVM you take the compiler with you into production

alexmiller 2020-03-26T17:49:13.084600Z

to really bake your noodle, Rich has played with some things to make all calls named parameter based so there is no fixed arity

👍 1
borkdude 2020-03-26T17:50:01.084900Z

thanks for the conversation - gotta run now

alexmiller 2020-03-26T17:51:27.085800Z

later

2020-03-26T18:00:53.086700Z

lul, I’m so used to cursive highlighting arity errors that I’d totally forgotten they’re not compiler-checked

➕ 1
2020-03-26T18:02:11.087300Z

I say that because it does add some amount of credence to the idea that tooling goes a long way here

seancorfield 2020-03-26T18:08:53.088Z

Likewise for Joker which is hooked up to an auto-linter in Atom for me.

orestis 2020-03-26T18:19:25.088600Z

I’ve hooked kondo to our CI - errors break the build :)

borkdude 2020-03-26T18:34:28.089Z

joker doesn't lint cross namespace arities btw, that was one of the first things I wanted to have in clj-kondo

2020-03-26T18:36:22.089200Z

Wait, you weren't? 🙂

2020-03-26T18:36:36.089400Z

With emphasis on the "you" 🙂

borkdude 2020-03-26T18:50:35.089600Z

we have a pretty big codebase and I didn't want to force it on my colleagues

borkdude 2020-03-26T18:51:23.089800Z

I do use it in my editor

borkdude 2020-03-26T18:52:35.090Z

but now that some of my colleagues are using it, and one has suggested doing using it in CI, may be a good idea to do it soon

borkdude 2020-03-26T18:59:27.090500Z

http://covid19.doctorevidence.com/ cloc output:

Clojure                         383           7862           2764          56302
ClojureScript                   261           9247           2296          51294
ClojureC                         56           1559            705          11184
Still about a 1000 linting errors + warnings. Getting rid of them slowly but surely as I'm working on the code.

borkdude 2020-03-26T19:01:29.091600Z

btw, sorry if I came across a bit unfriendly, didn't mean to. feeling a bit cranky this week.

seancorfield 2020-03-26T19:06:35.091800Z

I hadn't actually noticed that until you just mentioned it. Which I guess shows how rarely I have arity errors in my code? 🙂

seancorfield 2020-03-26T19:06:52.092Z

Is clj-kondo compatible with the Atom linter stuff?

borkdude 2020-03-26T19:07:24.092200Z

well, they aren't too frequent here either, but you know, there's always that one function in a code-path you don't hit during development, and heck, not even in the tests

seancorfield 2020-03-26T19:08:38.092800Z

Thank you!

borkdude 2020-03-26T19:09:01.093Z

to get cross namespace linting in your editor, you'll have to make a $PROJECT_ROOT/.clj-kondo directory, then clj-kondo will save analysis information there as you visit your files.

dominicm 2020-03-26T19:09:50.093200Z

No no, all in good jest. Maybe British sarcasm not coming across :)

alexmiller 2020-03-26T19:15:44.093500Z

I think we can all relate

💯 3
alexmiller 2020-03-26T19:16:08.093700Z

:)

seancorfield 2020-03-26T19:16:21.093900Z

I'll take further questions to #clj-kondo

telekid 2020-03-26T19:45:28.094800Z

I’ve dreamed about this - a language without positional arguments, only named slots

telekid 2020-03-26T19:47:53.095Z

where maps – not lists – get applied to fns

slipset 2020-03-26T22:19:45.097300Z

We run Eastwood in our CD pipeline. Lost count of how many times it has saved me.