Fork me on GitHub
#clojure
<
2018-06-04
>
vemv12:06:43

What's the biggest pain point of Component addressed by Integrant? I didn't get the idea from the readme

mpenet12:06:20

a "system" in integrant is described via data, in component it's actual code.

mpenet12:06:28

otherwise they are quite similar

dominicm12:06:57

@vemv you don't need to wrap & unwrap things so much with integrant. A good example of this is a connection pool, you don't need to do (:conn component), your integrant multi-method just returns the pool.

vemv13:06:10

gotchu. I was checking my Component db-pooling code and yeah it's exactly like that

vemv13:06:26

although, perhaps that could be tightly addressed at the level of the "injector" that puts the Component system into your request map

ackerleytng13:06:03

what are some best practices for placing specs? where would you place the specifications?

ackerleytng13:06:21

is there a place to put specs so that it won't be compiled for production?

vemv13:06:59

For this you can create a new source-path directory (just like src/test), enabling it only in dev/test envs. Then the new source-path would have spec-dedicated ns's

mindenaaron16:06:57

Hello Clojurians, Could someone help me with the spec registry? I store my specs in database and until now i've used a macro which s/def-ed them to the spec registry, but now i have to solve this without a macro, but can't figure out how on earth I could do that. I don't really like this registry stuff, strongly prefer stateless, functional solutions. How could I use my specs (often nested) without a registry or add them to the global registry dynamically via a function? Many thanks

Alex Miller (Clojure team)16:06:17

I’m not sure I have any good solutions for you but the registry is ultimately an atom holding a map of spec name to spec instance and the function behind s/def is s/def-impl which you can just invoke directly

mindenaaron16:06:51

that atom is actually private and def-impl is a no go based on docs

mindenaaron16:06:07

i want to avoid forking it just for myself

Alex Miller (Clojure team)16:06:16

well, you’ve already established that you don’t wish to go the expected path here

mindenaaron16:06:34

haha, Thanks Alex!

Alex Miller (Clojure team)16:06:46

I think invoking def-impl directly is fine in this case

mindenaaron16:06:33

I'm experimenting with it now, but i have to understand a lot

Alex Miller (Clojure team)16:06:40

you’ll be responsible for passing the form of the spec (the macro’s primary job is just capturing that)

👍 4
mindenaaron16:06:43

anyway spec is the best thing happened to me last year 🎉 thanks for your work!

Alex Miller (Clojure team)17:06:20

user=> (s/def-impl :a/b 'clojure.core/int? int?)
:a/b
user=> (s/valid? :a/b 100)
true

mindenaaron17:06:40

i see, thank you very much

mindenaaron17:06:04

I didn't really get the form part

Alex Miller (Clojure team)17:06:27

just the literal spec form for reporting

Alex Miller (Clojure team)17:06:59

s/def does take care (via res) of resolving deeply nested symbols

👍 4
mindenaaron17:06:16

i read the code

Alex Miller (Clojure team)17:06:18

depending how you’re storing things and what your specs look like, you may need to do more

Alex Miller (Clojure team)17:06:51

also, fyi there is #clojure-spec here

👍 4
mindenaaron17:06:35

i store my specs in postgreSQL backed duratoms, pretty extreme

shooodooken18:06:33

no purelyfunctional newsletter for the past 3 weeks and no repl newsletter for the past few months.. hope this is temporary 😞

jumar07:06:20

I got the last REPL on 5th May so that's "just" one month 🙂. The last http://PurelyFunctional.tv newsletter on 14th May so that's ~ weeks.

ericnormand14:06:51

Hey! It's coming back this week. I was just on vacation 🙂

👍 4
Nicolas Boskovic19:06:45

Speaking of PSQL, I'm having an issue with Korma - I'm trying to do large transactions through korma.db/transaction, but apparently the function isn't realized unless I print the results, which is something I'm trying to avoid since printing potentially 100k+ characters to stdout isn't very performant - I've tried doall, but nothing is working other than println. Any ideas?

Nicolas Boskovic19:06:46

The inserts are normal korma.core/insert funcs

ghadi19:06:31

doall on a vector doesn't make sense

ghadi19:06:46

(because a vector isn't lazy)

ghadi19:06:05

how large are a/b/c/d?

Nicolas Boskovic19:06:34

A and B can be small, but C and D can vary a lot I know a vector isn't lazy, but the rest of the application behaves as though it is and I'm not seeing the results I want in the database unless I'm doing the println

razum2um19:06:53

@alexmiller I remember years ago when I coming to clojure was asking why not including github in a language development process and was told about it was rich ’s decision. Did things change since then? Is today’s github coming to ms what he was(is?) afraid of?

Alex Miller (Clojure team)19:06:22

No, nothing has changed. And no, this is not something Rich was or is concerned about.

noisesmith19:06:08

@nnbosko did you expect the doall to realize the map calls inside the vector? doall isn't recursive and won't do that

Nicolas Boskovic19:06:53

So I should realize the map calls separately then

Nicolas Boskovic19:06:13

@tristefigure gave me a nice solution in #sql - (clojure.core/postwalk identity (doall ...)) works

sundarj19:06:07

@nnbosko map is for pure functions only, that's why it's lazy. if you want to run side-effects use run! or doseq instead

8
sundarj19:06:46

=> (let [x (map prn (range 2))]) 
nil                                       
=> (let [x (run! prn (range 2))])
0                                         
1
nil

sundarj19:06:40

any time 🙂

vemv20:06:46

Say I want my library to log errors, while not coupling itself to a specific logging-library choice (of the many available in the Clojure ecosystem), so all kind of devs can use the lib seamlessly. What should I do? I can think of: - use clojure.tools.logging (which I don't know that much) - use some interface I am not aware of - print to *out* / *err*, and make those bindings configurable I'm inclined towards the latter, but in that case you lose the goodies from specific loggers (like file/line info). Any established practice?

jumar07:06:07

@vemv Check https://spin.atomicobject.com/2015/05/11/clojure-logging/. I'd say the viable option is to use clojure.tools.logging with slf4j. slf4j is already an abstraction which is compatible with many java logging libraries. We use timbre but I've never really got very excited about it but even with timbre you should be able to use slf4j via https://github.com/fzakaria/slf4j-timbre

vemv14:06:16

Thanks! Good intro, the java landscape can be confusing. Not super sure though if c.t.logging is the absolute best for a library

darwin20:06:45

another option is to look into https://github.com/ptaoussanis/timbre, it should have no hard dependencies AFAIK

vemv20:06:32

Doesn't that introduce a problem if the consumer has a different logging-lib of choice?

vemv20:06:49

e.g. I want to handle all logging with a single configuration, without 'rogue' libraries

darwin20:06:04

ah, sorry, I missed “library” req in your post, scratch my post 🙂

👍 4
beders20:06:03

I'm about to try to convince a bunch of seasoned Java developers of the benefits of functional programming in general and Clojure in particular. What are you using to introduce new folks to Clojure, in particular people trained on OOP (but not necessarily senior enough to see the problems/shortcomings/best use cases for it) I'm talking hands-on training, maybe throwing in an exercise or two to compare approaches.

danielglauser20:06:22

I’ve found that taking a real world example from work, maybe a small service or utility, rewriting it in Clojure, and showing how quickly/easily you can get things done can be the most effective. By starting with a known example you step over the hurdle of knowing the domain, they just have to figure out the code.

12
the2bears20:06:48

^This. A few years ago we had to generate load for producing to Kafka... to test a hunch during some brainstorming on a bug. A couple Java guys were very impressed with how easy it was to whip up a test, change it, then close the discussion.

👍 4
beders21:06:09

I'm hesitant to show videos, especially the ones from Rick as they often touch on problems not yet encountered by more junior developers.

beders21:06:31

Yes, I'd love to take an example and have it re-implemented in Clojure.

beders21:06:36

Thanks for your suggestions

beders21:06:55

If anyone can recommend some slideware, that would be great