Nested “pistons” versus an individual piston for every task

I’ve searched the forums quite a bit for an answer to this, and if I have missed it, please direct me to where.

Reading through webcore basics series in this forum has been greatly helpful, and I have found some changes in my code in question I need to make to align with the best practices found there.

My question is, is it better to accomplish all related tasks in one large piston, executing sub pistons in one organized place, or have a bunch of individual pistons accomplishing these tasks, sharing information with global variables?

An example to this is I have a space I use HE/Webcore to automate everything from HVAC to lighting and security. For the HVAC, I created one large piston that controls two units and an economizer in concert with outdoor air temps and averaging multiple sensors across the space. This works well, but it is a little clunky I’m sure based on my own limited experience in writing webcore “code”. It spans about 350 lines and uses 13K+ of memory.

In my security applications, I experimented in using individual pistons running maybe ten lines a piece, all sharing data between the pistons using global variables. What’s the opinion on correct operation here? I suspect both are acceptable, but to me it seems more logical to place everything in one large piston.

do what is simpler and easier for you to understand.

generally this is keep them limited in scope and behaviors as this can be easier to debug and change function later

I find it best to keep a minimal amount of events triggering one piston.
You will get a lot of Yellow warnings. :slight_smile:
Debugging/Trace is simpler that way.

I break my code into subroutines and call pistons with args that use the same functionality.
These are basically procedures(args) but having functions() to return values would be awesome.
Old programmers die hard.

1 Like

Blockquote Old programmers die hard.

Agree. I love webcore but do long for the day where we can just freeform script. I understand why it’s written the way it is, but still.

When you say this, does that mean you have some pistons on your page that are the functions (procedures) and then some pistons that serve as a function controller to call the procedure pistons?

If so, that may be similar to what I have setup here as my test with several small pistons accomplishing a unified task.

Yes. Here's one block of pistons.
I call the subroutines for the house blinds from Blinds Day, Blinds evening, I'm Back and Away with args for open/close and the calling piston name for logs and debugging.
I also call the Locks routines for Good Night and Goodbye pistons

YES!