Fork me on GitHub
#clojure-dev
<
2020-03-26
>
borkdude16:03:56

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

mikerod16:03:37

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

mikerod16:03:06

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

dominicm16:03:14

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.

ghadi16:03:33

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

ghadi17:03:33

yeah that works

dominicm17:03:25

You'll gain a reputation if you repeat that enough

alexmiller17:03:17

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

dominicm17:03:53

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

alexmiller17:03:43

you make it sound bad

dominicm19:03:50

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

ghadi17:03:31

seriously, arity checking is overrated

ghadi17:03:02

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

ghadi17:03:29

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

ghadi17:03:50

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

ghadi17:03:11

arity is but one dimension

borkdude17:03:41

premature? this feature should have landed 10 years ago 😉

borkdude17:03:36

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 😉

borkdude17:03:28

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

alexmiller17:03:15

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

borkdude17:03:43

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

alexmiller17:03:05

in what context?

borkdude17:03:16

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.

borkdude17:03:35

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

borkdude17:03:45

unrelated to the arity error btw

ghadi17:03:21

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

borkdude17:03:49

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

mikerod17:03:10

seems like the arity argument was made quite clear

mikerod17:03:52

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

mikerod17:03:06

but think the conversation seems really dismissive here

alexmiller17:03:39

I'm not being dismissive

ghadi17:03:41

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

ghadi17:03:50

not leading with solutions

ghadi17:03:28

cost/benefit analyses

alexmiller17:03:32

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

borkdude17:03:00

I understand that too.

alexmiller17:03:33

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?

alexmiller17:03:30

I've never talked about this with Rich

borkdude17:03:35

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

mikerod17:03:39

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

seancorfield17:03:48

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.

mikerod17:03:56

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

ghadi17:03:57

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

borkdude17:03:15

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

alexmiller17:03:32

well that seems reasonable

mikerod17:03:43

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

seancorfield17:03:58

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

alexmiller17:03:21

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

borkdude17:03:42

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

alexmiller17:03:49

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

mikerod17:03:02

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

alexmiller17:03:46

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

ghadi17:03:30

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

alexmiller17:03:47

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

borkdude17:03:14

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

orestis18:03:25

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

andy.fingerhut18:03:22

Wait, you weren't? 🙂

andy.fingerhut18:03:36

With emphasis on the "you" 🙂

borkdude18:03:35

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

borkdude18:03:23

I do use it in my editor

borkdude18:03:35

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

borkdude18:03:27

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.

slipset22:03:45

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

ghadi17:03:31

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

alexmiller17:03:51

IFn doesn't tell you anything about arities

mikerod17:03:37

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

mikerod17:03:52

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

alexmiller17:03:01

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

alexmiller17:03:34

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

alexmiller17:03:05

that's a very Rich way to think about things

borkdude17:03:16

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

alexmiller17:03:36

sorry, I'm probably not being clear

borkdude17:03:54

do you mean metadata on IFn about arities?

alexmiller17:03:11

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

alexmiller17:03:26

so that widens the possibility of things that can be invokable

borkdude17:03:45

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

alexmiller17:03:13

well how do you check without the info?

alexmiller17:03:50

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

alexmiller17:03:19

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)

borkdude17:03:35

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

borkdude17:03:57

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

borkdude17:03:15

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

alexmiller17:03:55

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

ghadi17:03:13

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

ghadi17:03:49

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

borkdude17:03:52

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

borkdude17:03:28

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

alexmiller17:03:13

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

jake14219:03:28

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

jake14219:03:53

where maps – not lists – get applied to fns

borkdude17:03:01

thanks for the conversation - gotta run now

potetm18:03:53

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

potetm18:03:11

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

seancorfield18:03:53

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

borkdude18:03:28

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

seancorfield19:03:35

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

seancorfield19:03:52

Is clj-kondo compatible with the Atom linter stuff?

borkdude19:03:24

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

borkdude19:03:01

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.

seancorfield19:03:21

I'll take further questions to #clj-kondo

borkdude19:03:29

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

alexmiller19:03:44

I think we can all relate