Fork me on GitHub
#code-reviews
<
2024-03-21
>
Jonas Östlund07:03:16

Hi! How do you usually use *warn-on-reflection* in code bases for products that you are building? I am discussing this in a code review, where we have used https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#warn-on-reflection to point out files where we do Java interop. For any such file, clj-kondo will say error: Var *warn-on-reflection* is not set in this namespace. if there is no line (set! *warn-on-reflection* true) in that file. And based on those reports, we are now reviewing code where we have inserted a bunch of lines like (set! *warn-on-reflection* true) in different source files that do Java interop. But I am a bit hesitant whether or not it is a good idea to leave these lines in source code. I consider them more of a debugging tool that would usually not be part of the implementation. Instead, I would probably set *warn-on-reflection* for the entire code base from the deps.edn file instead, as suggested in https://stackoverflow.com/a/69790639 . What pros/cons do you see with either approach? That is, sprinkling (set! *warn-on-reflection* true) throughout the code versus having a single setting in deps.edn?

namenu13:03:38

Are you using tools.build? clojure.tools.build.api/compile-clj takes binding option as an argument.

Jonas Östlund13:03:24

It looks like we do. Thanks for the suggestion!

hiredman15:03:02

As an idiom it is all over clojure itself

seancorfield16:03:31

@U03JZS99P27 At work, we require that in every source file (and fail the CI build if someone checks in a file without it). We also run athos/clj-check across all our code and fail the build if new reflection warnings appear.