r/Clojurescript • u/_woj_ • Dec 11 '17
Core.Async Is Hard & Confusing
I have a background in the JavaScript world, and I'm used to making http request with APIs like fetch, promises, and observables. Coming to ClojureScript I was dumbfounded when I saw core.async syntax, and to be honest I still don't fully understand it. All these cryptic symbols and weird gotchas. It seems extremely complected and overengineered which is odd to me given that simplicity is one of Clojure's core values.
6
Upvotes
4
u/bostonou Dec 12 '17 edited Dec 12 '17
What is complected and overengineered? Seems like most of your complaints are about syntax, which is more of a problem of unfamiliarity.
Edit On second reading, this sounded more accusatory than I meant. It was meant to ask what was confusing to you and to encourage you in that the syntax isn't really a problem for very long.
3
u/dsrptr Dec 12 '17
My background was js too. I had used promises RX.js and others there, and also signals in elm so I was exposed to different ways to approach handling async tasks.
core.async is a bit lower level in the ladder of abstraction, but it pays off to learn it as it is quite simple, if maybe not easy. it also took me a bit to internalise its concepts.
what is that you are finding difficult exactly? maybe we can help here.
1
u/_woj_ Dec 12 '17
Another thing that makes it hard and confusing is the inconsistencies between JVM Clojure and ClojureScript. I get it that the platforms are fundamentally different with threads vs event loop, but it still makes learning for one platform more difficult.
3
u/halgari Dec 15 '17
Core.async is overused. Especially inside of ClojureScript projects. And yes, the code is hard to understand and is complicated, because async code is always that, complicated. Anytime you add non-determinism to a project you increase the complexity.
Anyways, here's a talk I did on core.async that talks about all of this and some ways to avoid the complexity: https://www.youtube.com/watch?v=096pIlA3GDo
2
u/_beetleman_ Dec 20 '17
core.async is really good lib but most of time you dont need it. I prefer use promesa which use core.async for few macros. If you using clojurescript you should check promesa. Good luck and have fun:D
2
u/xiongtx Feb 09 '18
It's certainly a different model for concurrency than promises / futures. You find it hard not b/c the CLJS itself is difficult to understand, but b/c you have to struggle with a new model of computation, a whole new idea. In other words, you're learning 😁.
What I'd do is to stop beating your head against CLJS for a while and go right to the source:
Concurrency in Go
core.async, and explains the whys and hows of concurrency much better than any CLJ(S) documentation does.A few big ideas:
Often, it can be helpful to separate a large program into smaller, independent parts
1
u/kanzenryu Dec 26 '17
One horrible thing in the documentation is "port". A term that we already ascribe a meaning to is used without introduction or definition. And then searching for port in the docs finds nothing.