Should there be a function to handle side effects in a behaviour tree

15 views
Skip to first unread message

Jay Shepherd

unread,
Dec 21, 2011, 6:14:52 PM12/21/11
to Flapjax
Hey Guys,
So i try and keep my behaviour tree functionally pure and only produce
side effects on the leaf nodes. So at the bottom of the tree im using
a mapE or liftB to react to the data change and update some part of
the system. But in my mind these should really be used for
transformation of data only.

So should there be another function lets say actionB, actionE that is
for side effects and should not return anything? If so can you get
this kind of encapsulation in js?

Or should there be no side effects because you use functions like
insertDom to directly update the dom and everything should be in the
tree

Or should i give up on purity ?

Thanks!

Arjun Guha

unread,
Dec 24, 2011, 11:37:26 PM12/24/11
to fla...@googlegroups.com
So should there be another function lets say actionB, actionE that is
for side effects and should not return anything? If so can you get
this kind of encapsulation in js?

In my own code, when I see this:

evt.mapE(function(x) { ... do not return ... });

I usually know that the mapE is only useful for its side-effects. I agree that it would be clearer if we had an actionE. Other names? consumerE? doE?

Or should there be no side effects because you use functions like
insertDom to directly update the dom and everything should be in the
tree

I find insertDomE useless half the time; all it does it provide an *illusion* of purity.

This is an example of insertDomE being *useful*, since the element itself is time-varying:

insertDomE(timerB(1000).liftB(function(t) { return DIV(String(t)); }), 'target');

But, I often use insertDomE in the following manner:

insertDomE(DIV(timerB(1000).liftB(function(t) { return String(t); }), 'target');

Above, insertDomE does nothing useful since the DIV is static (even though its internals are time-varying).
Therefore, it is equivalent to:

targetParent.appendChild(DIV(timerB(1000).liftB(function(t) { return String(t); }));

I think the latter is better code.
 
Or should i give up on purity ?

Such a broad question! I think so, yes.

Arjun
Reply all
Reply to author
Forward
0 new messages