3 ms·
This looks nice. Less readable than Go (is there GoScript yet?), but still fairly straightforward. One remark I'd like to make is that I don't see this as havi
by alco 13y ago
This looks nice. Less readable than Go (is there GoScript yet?), but still fairly straightforward.
One remark I'd like to make is that I don't see this as having a big advantage over FRP.
The examples with mouse coordinates look like an imperative approach to FRP. With the latter, one wouldn't have to explicitly set up a channel and read from it -- that is an implementation detail in FRP.
To emphasize the contrast, I'd call this channel-based approach an Imperative Communicating Programming (ICP). Your code does not react to changes like it does with FRP. Instead, you as a programmer ask for changes, very often in an infinite loop, and then transform those changes into a side-effect in the browser.
On one hand, channels + goroutines provide a single abstraction with which it is kind of straightforward to implement various concurrently executing threads of code. On the other hand, those infinite loops and their proliferation in the channel-based code will definitely cause some people to cringe and go with FRP instead.
I don't think FRP is as applicable as channels to as many use cases. Channels are more low level and therefore more potent. But for what FRP does, it provides a better (read "more concise", or "declarative") abstraction for it.
- swannodette 13y agoNote that in some ways core.async is a bit more flexible than Go - for example you can dynamically select over a changing list of channels. I've found this to be really handy especially when you're receiving channels on channels. you can do everything in an FRP style if you like with core.async, it's flexible enough for that. But I think for less toy examples this is undesirable as you allude.
- mseepgood 13y ago> Note that in some ways core.async is a bit more flexible than Go - for example you can dynamically select over a changing list of channels http://golang.org/pkg/reflect/#Select http://golang.org/pkg/reflect/#Select
- swannodette 13y agoYou should look a bit more closely at what I said :) EDIT: Oops, I didn't see you had linked to the reflect features. I did not know that and that is very cool.
- mseepgood 13y agoYou said: "for example you can dynamically select over a changing list of channels" reflect.Select does exactly that.
- jzelinskie 13y agoGo has a trick where you can set a channel to nil in order to get its functionality ignored in your select. If you gave the select all the possible channels and turned them on and off rather than adding/removing channels you can obtain similar functionality.
- swannodette 13y agoYes you need to know all the channels ahead of time, this restriction simply doesn't exist in core.async.