component

2025-09-03T14:09:49.089089Z

What are the disadvantages of using component ? https://youtu.be/13cmHf_kt-Q?t=2429 https://youtu.be/13cmHf_kt-Q?t=218 Clojure namespaces are not instantiable, but they define the dependencies in terms of code that the ns requires in order to function, (and thanks to cljkondo, if it's unused will be hinted) I think with a system map we loose the connection to this clojure source code functionality, and passing a map that is the construction of all dependencies of a system, we can no longer look at the ns declaration and infer the dependencies anymore. Can you share your opinion about using an indirection mechanism to pass dependencies around ?

lukasz 2025-09-03T14:13:46.182099Z

sounds like you want to try https://github.com/tolitius/mount to understand why using namespaces and vars as basis of systems is a bad idea ;-)

lukasz 2025-09-03T14:15:28.381309Z

the only true issue with Component (after using it for ~10 years) is that declaring dependencies is disconnected from the code that uses them - e.g. your ring handler expects a database connection to be provided, but you forgot to specify it in the dependency list and you get an NPE

2025-09-03T14:19:34.206049Z

Even mount I think is too magical.

lukasz 2025-09-03T14:21:59.409539Z

yes, I tried it briefly and it reminded me of my early attempts of writing Clojure as if it was Ruby, global mutable state everywhere and things materializing out of nowhere

2025-09-03T14:24:40.578149Z

The objection to mount and plain def is the global var argument. One cannot run two instances of the same system on the same jvm process. That is not practical. If the norm is to configure a system via env (from twelve factor app) you are not going to run two systems anyway. Have you ?

lukasz 2025-09-03T14:25:37.047969Z

yes, I frequently would run dev system serving local requests while running tests which use a test version of the system

2025-09-03T14:29:36.297099Z

do you use tools.namespace to reload your code in dev mode ? how that interferes with the running test system. I think it wipes the namespace and crashes the test system, right ?

lukasz 2025-09-03T14:33:09.691549Z

yes, it's something that does happen but it's recoverable - although admittedly understanding how to work with tools.namespace and make it part of my workflow took a while

Steven Lombardi 2025-09-03T14:38:32.901029Z

> Declaring dependencies is disconnected from the code that uses them > When you create a component, if you declare your own constructor fn next to the defrecord, you can create the component wrapped in a call to component/using and then everything lives together. You no longer need to add those deps with component/system-using wherever you assemble the system.

Steven Lombardi 2025-09-03T14:40:32.258009Z

This only works assuming the system key is identical to the key in the component. Or the mapping between the two is well known and not arbitrary.