beginners

Pyi Soe 2025-05-15T08:06:02.673969Z

https://caveman.mccue.dev/tutorial/clojure/27_run_tests_against_your_database In the above tutorial,I found that (PostgreSQLContainer/.getPassword container) is used instead of just (.getPassword container) . Is there any practical reason to use (ClassName/.someInstanceMethod obj) syntax?

p-himik 2025-05-15T08:31:55.201279Z

In that context, it's needed to avoid reflection (as indicated by the warnings you'll get when loading that code without PostgreSQLContainer/, due to the (set! *warn-on-reflection* true) form above) that would happen because container doesn't have a type known to the compiler. However, you can still use (.getPassword ...) and have no reflection if you type-hint container. It can either be done at the binding site - (let [^PostgreSQLContainer container ...] ...) - or in the function that makes the container:

(defn start-pg-test-container
  ^PostgreSQLContainer []
  ...)
I'd say the latter is better because then every start-pg-test-container call site will have the type info.

👍 1
p-himik 2025-05-15T08:39:28.989179Z

Also, FWIW I would probably use .getJdbcUrl and add username and password to it instead of constructing the whole URL myself. Something like this

(defn start-pg-test-container
  ^PostgreSQLContainer []
  (let [container (PostgreSQLContainer.
                    (-> (DockerImageName/parse "postgres")
                        (.withTag "17")))]
    (doto container
      (.withUrlParam "user" (.getUsername container))
      (.withUrlParam "password" (.getPassword container))
      (.start)
      (.waitingFor (Wait/forListeningPort)))))
And with just :jdbUrl (.getJdbcUrl container) in get-test-db.

👍 1
Gent Krasniqi 2025-05-15T09:13:37.876969Z

In my case stuff like this often ends up in the explicit form just because I initially used it for auto-completing the method I was after...

p-himik 2025-05-15T09:28:52.665989Z

At least Cursive can with reasonable reliability offer sensible auto-completion even when there's nothing else in the form. I guess based on the context, I dunno.

Pyi Soe 2025-05-15T09:29:40.941649Z

p-himik, Thanks! I was asking ChatGPT and it can't help much. just keep answering that (.someInstanceMethod obj ...) is the correct way.

Pyi Soe 2025-05-15T09:33:19.265479Z

Yes, I just checked and it seems Cursive can still show methods available for auto-completion.

Gent Krasniqi 2025-05-15T10:55:03.320309Z

I think emacs (cider) also can do that if you start with the object already stated e.g. (.<cursor> object), but I guess I'm not into that habbit yet.

2025-05-16T02:57:03.890349Z

aside, is (Foo/.bar o) a new syntax, or is it just something I don't remember seeing?

p-himik 2025-05-16T08:47:57.538269Z

New in 1.12. And there are some other new things.