Fork me on GitHub
#babashka
<
2023-03-29
>
joost-diepenmaat08:03:32

Hi, I’m getting an error “Method close on class sci.impl.deftype.SciType not allowed!” — is that something specific about close or a more general issue?

borkdude08:03:27

@U09N5N31T it depends. can you provide a full repro?

borkdude08:03:27

deftype in general has only limited support in babashka. it's probably better to avoid it and write your own close! function

joost-diepenmaat08:03:08

I think something is wrong with our code — looks like it expects a close method in a protocol to implement a .close java method and that is probably not correct

borkdude09:03:55

In that case you could call the protocol method without interop:

(protocol-ns/close ...)

borkdude21:03:41

@U09N5N31T did you manage to figure it out?

joost-diepenmaat07:03:49

@U04V15CAJ yes we found the cause and adopted a workaround. Using the protocol clojure function instead of the interop method, as you suggested, works: https://git.sr.ht/~rwv/cljs-exif-reader/commit/ee3d94da53133f58b581f09964e84134721703eb

🎉 2
borkdude09:03:34

@U09N5N31T are you planning to announce this lib somewhere? else I can make a shout-out of it here in the bb channel or elsewhere

joost-diepenmaat10:03:55

A shoutout would be nice! you can link to here: https://git.sr.ht/~rwv/cljs-exif-reader

vemv11:03:29

Context: I don't follow bb stuff very closely. Although I sympathize with it :) Can I lint that my .clj files can be run through bb? So that I can rest assured that others can run my scripts as they please.

4
borkdude11:03:46

@U45T93RA6 "Can I lint", what does this mean?

vemv11:03:30

the linter returns 0 iff the .clj file is bb-compatible

borkdude11:03:16

ah, like that. no, this doesn't exist yet, but there is or was an issue for it in clj-kondo :)

vemv11:03:01

Good to know!

borkdude11:03:37

The best way is to just try it out and see (and ask questions here)

vemv11:03:37

My bandwidth is fairly limited to try things out, unfortunately. As hinted I'm not primarily a bb user. Although I could follow something like a brief doc guide (or eventually linter) on how to keep compat (e.g. avoid this construct or lib) This is merely a suggestion though - currently I don't have a pressing scenario

borkdude11:03:31

Those docs are a bit out of date though

borkdude11:03:34

to ensure compatibility when writing libs, I usually use the cognitect test runner and run tests for both jvm and bb

lispyclouds11:03:43

> Those docs are a bit out of date though yes not sure whats the reference for the differences are now. the book is in a similar state i think as well?

borkdude11:03:00

we should link to the book from the README and then update the book

borkdude11:03:24

but in summary: to ensure compatibility: it's best to run the tests you've already written for JVM Clojure and run them with bb and run those tests in CI.

teodorlu11:03:57

I also want this! (I think I've asked about it before). I would prefer to only write babashka-compatible clojure. So I'd want to opt in globally so that my linter for clojure files warns me each time I'm doing something that won't work in babashka.

borkdude11:03:53

What is not babashka compatible is constantly in flux (going towards clj compatibility, not the reverse) so maintaining that linter is like maintaining the docs: it will always go stale. Running tests is the best remedy against that

👌 2
borkdude11:03:59

Just loading the code in bb (executing the top level defn, etc) will already tell you a lot: references to Java libraries that aren't in bb, deftype with Java interfaces, etc

borkdude11:03:12

As a rule of thumb, it's best to stick to normal functions and data structures, avoid external Java libraries, avoid doing interop in the name of better performance (it works, but it's less performant in bb), just use the core functions, avoid custom data structures/types (it can be done, but it is not fully supported and less performant)

👍 2
2
teodorlu11:03:51

So a CI smoke test that just tries to load it all in a babashka interpreter might be a "good enough" solution? Or a "unit test" that does the same?

👀 2
borkdude11:03:50

unit tests > smoke tests, of course

👍 2
borkdude11:03:29

if you're running tests in CI with the JVM, run them with bb as well

👍 2
🎯 2
vemv11:03:24

it's a legit approach though, especially if I don't have tests for my scripts

borkdude11:03:12

@U45T93RA6 if you don't have tests for your script, it's easy enough to find out if it works in bb by just running it with bb instead of clojure?

vemv11:03:07

then we're back at the original point i.e. I just want to keep the script for others to possibly run with with bb throwing a few linters at a script is easier (and less side-effectful) than running it

borkdude11:03:48

yes, but if the linters don't complain it's still not a guarantee that it will work, it's only a good initial indication (which may go stale)

vemv11:03:36

even if it's a "code loader" instead of a linter? ...anyway, I was just testing the waters, I expect nothing 😇

borkdude11:03:40

@U45T93RA6 it depends on how you set up your script. if you set it up as something that doesn't cause top level side effects, you can use bb as the code loader to probe incompatibilities

teodorlu11:03:12

"linter as dockerized/isolated code loader smoke test" is an interesting idea

🙂 2
borkdude11:03:12

well, there's bb docker images, so have at it ;)

🎉 2
teodorlu11:03:32

definitely possible to solve in userspace without changing babashka or clj-kondo 🙂

lread17:03:15

I guess a linter would be interesting. Like, "hey, what you are doing here, my friend Lee, definitely won't work with bb". But to claim bb compatibility for a lib, I'd always run the lib test suite under babashka itself.

👍 2