Isn't core.async contrary to Clojure principles?

后端 未结 6 2022
日久生厌
日久生厌 2021-02-01 13:45

I have seen many Clojure programmers enthusiastic about the new core.async library and, though it seems very interesting, I am having a hard time seeing how it conforms to Cloju

6条回答
  •  伪装坚强ぢ
    2021-02-01 14:02

    Every programm has two parts, one part that is always non function talk data in, spit it out and so on. For this part we know have core.async, it is ture that core.async has mutable things, but note two things. The state of the channels is basiclly managed by the library. The things you put on it are, what on might call flowstate. Meaning that when you put something like a channel you do not expect to come back at it, or even change it.

    Core.async is nice to manage this part of your programm. For the rest, all the transformation and calculation on your data, clojure tries its best to give you good tools to do it functionally.

    It seems to me that this prevents simplicity and composability. Why is it not a problem?

    There are two worlds, the sync and the async world. You can put stuff, or take stuff out of the async wrold with put! and take! but other then that (and maybe some other function) these to worlds are seperated from each other. Clojure does not want to become a completly async language. The functions and data transformation are what need to be composable.

    Maybe as a consequence of the previous two issues, a lot of code with core.async uses lower-level constructs such as loop/recur instead of map/filter/reduce. Isn't it a step backwards

    Operation like that over channels will be possible. Core.async is still young and not all possible construct and functions have been written yet.

    But in generally if you have large data transformations you dont really want to do them in async world, you want to have them in a collection and then throw something like the reducres framework at it.

    The main thing to understand is this, core.async is not the new standard, its just one more thing that helps you programm. Sometimes you need STM, sometimes Agents, sometimes CSP it depends and clojure wants to give you all the options.

    One reason people like core.async is because it helps with some stuff that is otherwise really hard to handle, like dealing with callbacks.

提交回复
热议问题