Objects or pulses? Or some other way?
XOD aligns best with a stateless (cf. functional, or dataflow, or clock-driven-EE) style. But, many useful things require a sequence of actions, and/or maintain some state. In the c++ world, those are usually objects & methods. And, many Arduino IDE libraries are written in that style (and even some XOD libraries).
It seems necessary to me that we need some mechanism to thread, or chain, nodes (methods) so that things happen in the right order. Is it (usually) a better practice to use pulses, or the object?
Typical Arduino IDE classes have a pattern of: construct object, call .begin(), do-some-action, get-some-value, etc. Here’s an example for neopixels in XOD:
We want a pixel to turn on, some time to pass, then another pixel to turn on.
As you can see in the screen-shot, this attempt was to use the “object” as the thread/chain mechanism. It seems to be a plausible mechanism. However, other things in XOD like “pulses” better (“select”, “branch”, “delay”, etc.), and already exist. The “gate-delay” is just a composite I made.
Here’s the same thing using pulses to chain things:
Which doesn’t require the composite delay-gate, so uses less nodes. But, the “method” nodes all need “trigger” now.
Here’s another one: turn on a pixel (pixel_index=step), but when the step-value is zero, clear the string first. So, like an if:
if step == 0 {
clear-string()
}
set-pixel-color(step, …)
show()
Using the object to chain things, I worked out this:
But, here it is using pulses:
It actually takes more nodes, because it has to produce a pulse from the step’ping (actually, there is a pulse available in this case, from the clock that drives the counter, but, for illustration purposes…). I also don’t like that “pulse-on-change”. I may be confused about whether I need something like that. I was tempted to use “pulse-on-true” (and pulse-on-false), but I wouldn’t get a pulse for every step.
I notice that xod-dev/w5500 has a mixed model. Some nodes take the object (e.g. xod-dev/w5500/lan-ip), and some take pulses. I think that nodes that only take the object are saying “do this only once (as setup)”.
I haven’t done that much XOD coding, so what’s your experience of what works best? Objects or pulses? Other? I’m hoping we can produce a guide from this discussion (especially for me, and especially for my arduino-to-xod library converter).
If that wasn’t enough to think about, don’t forget getters, setters, and instance-variables.