core-async

2020-12-17T15:30:45.302600Z

Is there a general best practice relating to passing a mult to functions which then "create" their own channels to do what they need, or leaving it to an outer assembly layer to create the chans that are needed first and pass them to the function? Are there any factors that help guide this decision? I keep going back and forth on it

alexmiller 2020-12-17T15:32:30.303Z

there's a chapter about this in Clojure Applied if you want to read that

2020-12-17T15:33:17.304100Z

Actually that's what got me thinking more about it 🙂 There you generally suggest the latter, assembling from the outside of the function right?

alexmiller 2020-12-17T15:33:19.304300Z

in general, I think externalizing channels is a good idea (unless you rely on properties of those channels like buffer policy or transducer)

1👍
2020-12-17T15:34:01.304900Z

[great book by the way probably my fav clojure book!]

alexmiller 2020-12-17T15:34:19.305100Z

what's missing that you would want in a 2nd edition?

2020-12-17T15:40:53.305300Z

I think I might have had thoughts on this when I last did a thorough reading maybe a year ago but I can't remember now. I'll skim it again tonight and let you know if anything jumps out. It's probably just the obvious stuff though like spec, and I'd be interested to know if anything would change relating to the usage of records vs maps

2020-12-17T15:44:27.305500Z

In general I like how it really goes into "composing a system", basically the whole section 2. But not sure a whole lot has changed on that over the years

alexmiller 2020-12-17T15:46:00.305700Z

thx, let me know if you think of something

alexmiller 2020-12-17T15:46:07.305900Z

I have my own list of course :)

1👍
2020-12-17T19:28:59.308200Z

It seems like an assembly layer is nice and certainly cleaner, but greatly increases development time and ongoing maintenance complexity. OTOH having functions orchestrate their own channels internally as black boxes presents a cleaner interface from the function to the outside world, but might become brittle later in certain combinations with other things. Any thoughts? (I haven’t read the book yet, just spitballing…)

2020-12-17T20:02:55.309700Z

Something to keep in mind is core.async is all side-effects, so architectural discussions of state and side effects are applicable

2020-12-17T20:07:23.311600Z

in general, the community around clojure is much more accepting of side effects that are not visible (mutating transients while creating them and returning immutable values), vs creating a mutable arraylist and returning it.

2020-12-17T20:11:48.314400Z

Another thing to keep in mind is core.async uses global resources (the thread pool, and for anything non-trivial timers) so multiple core.async "blackboxes" will be entangled there

2020-12-17T20:36:20.320100Z

And another thing, core.async isn't the best at timely resource management (it can hang onto references to things longer then might expect), so "externalizing" (creating it at the top most visible level) that stuff can help keep track, analogous to a C program managing memory by just allocating all it needs up front

1❤️
2020-12-17T20:39:54.320300Z

good tips, thanks!