Fork me on GitHub
#polylith
<
2023-01-16
>
xceno10:01:14

What's the general opinion regarding common utilities and where to put it? For example: Imagine a namespace like this: https://github.com/plumatic/plumbing/blob/master/src/plumbing/core.cljc Full of functions like:

(defn sum [xs] (reduce + xs)
Normally I'd have a libs folder with such namespaces and just require them as usual. A component with these common functions would be required everywhere over time. And hiding everything behind an interface ns and forwarding the calls, doesn't seem to add much value right now. Am I wrong?

jeroenvandijk10:01:42

Not sure if it is considered good Polylith practise, but I have some local libraries in a libs dir. For these libraries I am somewhat missing features of Polylith (like incremental testing), but putting these libs in components doesn’t feel right either. Curious to hear others opinions about this as well.

Teemu Kaukoranta11:01:37

If you want to use components, you can define the implementation in the interface namespace, or have an interface folder, with (implementation) namespaces inside. For example acme.utils.interface.math

Teemu Kaukoranta11:01:56

I agree it feels a bit odd

jeroenvandijk11:01:54

yeah I have one case where I do that. And for protocols and multimethods I use acme.utils.interface.protocols

jeroenvandijk11:01:39

and for implementation of the “protocols” i used acme.utils.interface.extensions . But for libraries I have not found something I liked

ikitommi12:01:45

One solution would be to allow setting :interface-ns per component. For libraries, one could use the top-level ns (e.g. acme) and get all the code from the component as an interface. Or a way to mark a component as a :library and drop the whole interface convention from those.

seancorfield18:01:15

We do what Teemu suggests and just have the implementation in the interface file. You don't have to have a separate impl file for every interface -- you could always refactor parts of that later.

xceno20:01:53

Thanks everybody! I'll play around a bit and see what I like best. Just using direct implementations seems like a good compromise though on first glance, we'll see