Generic discussion of good programming practice


Today I almost accidentally wrote a piston that would be problematic. I found, after I’d created it, that it was relying on a change in a global variable as the trigger. And I remembered the discussion on problems with transitioning to Hubitat, and how many of them seemed to be occurring because of pistons that were firing upon changes in global variables.

I went back and changed the piston so that the action that set the global variable was also the trigger that caused the piston to fire. That way the global variable remains available as a reference for other pistons, and the system is not continuously looking for a change in that variable.

So it got me thinking: what are some other general guidelines that we can offer each other to help our pistons (and perhaps programs in other environments) work better?