Fork me on GitHub
#beginners
<
2023-12-25
>
Nim Sadeh04:12:23

For those using environ to manage environment variables during dev/prod, what do you use to pass a large number of properties when running your uberjar? Seems like there's no easy way to pass a file s.a., a .env

Bailey Kocin04:12:36

I usually use a mix of data defined in EDN files and then use ENV values to override these values in live running environments. You can bundle data files in the JARs and read them!

practicalli-johnny08:12:09

Environ can read from a Java Properties file (although the Environ project doesn't provide an example) The Java properties file could be used to define values for environment variables (although I advise against using any file secret and sensitive values) Other libraries that have application configuration use a file containing a hash-map, e.g donut-party/system, Integrant, etc.

Nim Sadeh14:12:34

Interesting, where do I put it?

practicalli-johnny20:12:16

Config usually goes in a resources directory and included on the project classpath, so those files are included when creating a jar

👀 1
Can12:12:26

I have a Clojure expression that I want to execute only once when a specific function is called. I've tried using the ^:once metadata tag as follows:

(^:once #(+ 4 2)) 
What is the correct way to ensure that a particular expression is executed only once within a Clojure function? Are there alternative approaches or best practices for achieving this? Or if my approach is correct? Thanks 🙂

Can13:12:30

If possible, I don't want to use delay to solve my problem.

Ed13:12:44

You could also look at memoization. Clojure includes a function for that https://clojuredocs.org/clojure.core/memoize which provides very little control as to how items get removed from it's cache. There's also https://github.com/clojure/core.memoize which will give you more control.

practicalli-johnny14:12:29

defonce ?? Or update a value in an atom the first time the expression is called, surrounding by a check of the atom value each time the expression should be called, skipping if there is a value in the atom.

seancorfield17:12:01

> I don't want to use delay to solve my problem Could you explain why not? Using delay is typically what folks use for "evaluate on-demand only once".

Can18:12:37

@U04V70XH6 Honestly, there is no specific reason. I just want to learn different approaches. I haven't used delay before, so I'm not entirely sure about it(Because I am newbie in Clojure 🙂). If you advise that it's okay to use, then I will give it a try.

Can18:12:12

Thank you so much, it is worked as I expected 🙂

🔥 2
Nim Sadeh17:12:53

I read https://clojure.org/guides/spec and my takeaway is - wow, that's really cool, I want to use it everywhere. But then I look at Clojure code and see that it's used sparingly. Why is that? Are there guidelines for when to (not) use spec?

seancorfield17:12:33

Rich talks about this in a couple of his presos. Specifically Spec-u-lation I think. The TL;DR is that Spec is good at the boundaries but is not needed "everywhere". During dev/test, you might use Spec more heavily (perhaps instrumenting functions during testing, generating test data, generative testing, etc), but for production usage you mostly use Spec around the edges of your code. Maybe this will help? https://corfield.org/blog/2019/09/13/using-spec/

🙌 1
Alex Miller (Clojure team)19:12:28

The two sweet spots are information structures (keywords maps etc) and syntactic forms. The core specs focus on the latter, since the former is more typical in application domains

Nim Sadeh19:12:39

What do you mean by syntactic forms?

seancorfield19:12:43

Code. As in macros. Several core macros have active specs (such as ns).

👀 2