Fork me on GitHub
#clojure
<
2024-01-09
>
borkdude15:01:07

Can anyone check their code-bases for usages of clojure.reflect and what functions from that namespace you use? ๐Ÿงต

borkdude15:01:44

I wonder if anyone uses more than just reflect/reflect. Upvote this message if you're only using reflect/reflect , specify others in thread below

upvote 3
p-himik15:01:09

Is the answer "I don't use it at all" useful?

๐Ÿ‘ 8
1
borkdude15:01:27

Sure, let's upvote your answer if other aren't using it either :)

wikipunk15:01:30

I use reflect (datafy also uses it for classes)

borkdude15:01:59

@U23DRD8FN "and what functions from that namespace you use"?

wikipunk15:01:23

I mean just reflect function itself

๐Ÿ‘ 1
borkdude15:01:30

@U0P0TMEFJ what did you mean with the upvote ?

borkdude15:01:50

please be explicit about what functions exactly you are using if more than just reflect

Ed15:01:04

I meant to upvote only reflect/reflect

borkdude15:01:19

๐Ÿ‘

๐Ÿ‘ 1
Darin Douglass16:01:02

https://grep.app/search?q=reflect/&amp;filter[lang][0]=Clojure looks like mostly just reflect/reflect, though there is at least one use of reflect/typename

Noah Bogart19:01:25

Is it possible to avoid loading user.clj when the containing directory is on the classpath? i only want user.clj to be loaded when starting a repl

hiredman19:01:25

no

๐Ÿ‘ 1
seancorfield19:01:10

Put it in a dev folder and use an alias when starting a REPL that has :extra-paths ["dev"]

โž• 4
Noah Bogart19:01:10

it's actually an issue with running the tests with -M:dev:test:runner (where :dev has "dev", :test adds "tests", and :runner has the main-opts). i have some both dev and test related functions in the dev directory, but it seems one of my dev dependencies doesn't compile correctly, so I'm struggling to use :gen-class in my main namespace. an annoying situation to be in lol

Alex Miller (Clojure team)20:01:12

or, just don't ever use user.clj :)

Noah Bogart20:01:30

i'm also considering that too

Joshua Suskalo20:01:24

I recommend a dev.clj instead of the usual user.clj, which can easily be used from the repl, but which must manually be invoked to resolve this exact issue.

๐Ÿ‘ 4
Noah Bogart20:01:59

that's clever, thanks

Joshua Suskalo20:01:23

If loading it takes a long while too then you can throw a (println (char 7)) in there as well right at the end of the file so that you get a bel character printed, and if you've got your terminal or editor configured to notify on bel, then it can help get your attention too.

Noah Bogart20:01:07

My issue is just a combination of requiring a dev library that can't be compiled, with :gen-class in my main namespace

๐Ÿ‘ 2
dharrigan20:01:45

We also use dev.clj at work dev/src/dev.clj - solves a lot of user.clj issues ๐Ÿ™‚

hiredman20:01:00

I don't think you really understand the issue you are having, because I would be really surprised if the :gen-class directive in an ns form had anything to do with it

Noah Bogart20:01:54

๐Ÿคท maybe not. if i remove (:gen-class) from the main namespace (the namespace with -main in it), then everything works. if I remove the specific libraries from the :require block in my user.clj file, then everything works. if i have both, then running clojure -M:dev:test:runner fails with ClassNotFoundException pointing at the main namespace

hiredman20:01:57

The issue is likely to be actually something like your user.clj is loading some library before clojure.core/compile is called causing that library to be skipped when doing transitive aot compilation

๐Ÿ‘ 1
hiredman20:01:41

Ah, yeah, you are loading stuff in user.clj before compilation, and compilation is a side effect of loading, and already loaded stuff doesn't get reloaded, so if it is already loaded it won't be aot compiled

๐Ÿ‘ 1
hiredman20:01:28

So the other option is don't transitively load stuff from user.clj, use requiring-resolve, etc

Noah Bogart20:01:17

thanks for the details, that's helpful to know

seancorfield20:01:16

user.clj seems to be such a footgun... there are so many "issues" that we see here on Slack with people running into problems like these:slightly_frowning_face:

Joshua Suskalo20:01:56

Part of me wonders if it would be a good idea to have the code that loads the user namespace file print a warning if it finds the file before it actually loads it.

seancorfield20:01:46

Well, the people who run into trouble expect it to be loaded so I don't think that would help.

seancorfield20:01:09

The problems aside from what they put in user.clj

Noah Bogart20:01:40

it is strange to me that it's loaded first, but I guess it must be, otherwise, how would it be inserted into the chosen namespace?

Joshua Suskalo20:01:56

No, like a warning saying "loading a user.clj is a dangerous operation. It may cause your repl to fail to start if issues exist elsewhere. It is recommended you migrate to a namespace which is not automatically loaded."