Fork me on GitHub
#core-async
<
2020-04-12
>
Eddie19:04:51

I'm curious if anyone has thoughts on naming conventions for naming channels. My understanding is that part of the beauty of using channels is that producers become agnostic to consumers and vice-versa. I have been struggling to get that same elegance in the organization of my code. For example, the following code is pretty clear but it does imply that from-file will always be a channel of objects from "the input file" and to-file will always be a channel that feeds into "the output file".

(let [from-input-file (chan 1)
      to-output-file (chan 1)
      xf ...]
  (pipeline 4 to-output-file xf from-input-file)))
It seems equally (un)helpful to name the channels pre-xf and post-xf because both naming conventions imply producers and/or consumers in some context. Maybe it is best to name channels based on what they "hold"? For the above example, maybe raw-data and clean-data depending on what xf does. I hesitate to do this because I have been warned not to think of channels as collections. Any thoughts or suggestions is much appreciated.

Timur Latypoff20:04:11

Would in and out work?

👍 4
Ben Sless20:04:24

^came here to post this. Unless there's extra semantic meaning you need to pass around (more than 2-3 channels), in/out are good enough. They're sort of like ports of your process

👍 4
Eddie20:04:44

I would imagine that for a small toy example like the above, yes definitely. For the general case where an application might have many channels (some may even be global) you might need more semantics.

Timur Latypoff20:04:05

I actually also encounter this problem of naming multiple channels well. But also whenever I have more than 3 channels in one place, it becomes difficult for me to juggle them, and the code becomes really messy, so I try to restrict myself to just 3 at a time (and I also found async's mult, pub, and mix very useful in simplifying my code)

Eddie20:04:10

Thanks for raising mult, pub , and mix ! I am unfamiliar with them. Just read the docs and although I don't fully grok them yet, I can see how they are helpful for defining a larger flow out of a few channels.

👍 4
otfrom08:04:55

I tend to name my channels like I name my seq like things, but I do append-chan on to them if appropriate