On Sunday, 19 July 2015 02:05:01 UTC+3, Samuel Lampa wrote:
On Saturday, July 18, 2015 at 3:54:12 PM UTC+2, Egon wrote:
PS, if you are experimenting with FBP you might be better off declaring a supporting framework for it:
So, in short, this is exciting that a framework can be written with this little code, and allowing such a nice and terse syntax!
I guess you know about GoFlow [1] though? I have been playing around a bit with that (e.g. creating a toy component or two [2]).
Few years ago, yes, I looked at it.
What I have been trying with the examples listed above though, is to see how far I can go completely without a framework, by just following a determined pattern, and relying on the in-built concurrency primitives in Go.
Your mini-framework looks really nice though! (You wrote that in under 1 hour?!
Yup :)
:) ) It will be good learning material for me :)
One thing I wonder though, that I wasn't able to figure out from the code yet (newbie as I am), is whether the communications are happening across normal go-channels, or whether a reflection call is needed on receiving from the in-ports? (I'll study the code more, but thought it be faster to get some pointers :) ).
Currently it relies heavily on reflection in the driving loop:
For performance, instead of wiring things together at runtime you can generate the code. I.e. generate the same code you have in the "frameworkless" approach, it shouldn't be too difficult.
You can avoid the channels by writing the nodes as a function/method:
func Split(v string) (left, right string) {
m := len(v)/2
return v[:m], v[m:]
}
Then use some declaration, such as:
Node{Func: Split, Ports: {"In": 1, "Left":-1, "Right":-2}}
Here you have to use numbers to pick out the values, reflect doesn't provide a way to get the names of the in and out params. Once you have declared such functions you can wire them together. But this will still have the func call overhead, so it might make sense to work on batches instead of strings. I.e. have a node that converts 100 string-s and outputs []string... basically all the nodes work on a batch of strings instead of a single string.
But if performance is a real consideration I would combine channels at the top-level (without a framework) and try to create heavy-loops inside the nodes. Each node slows things down.
I'm not sure why particularly you are using FBP and what problems it solves for you, I find the "regular Go code" nicer to work with.
+ Egon