Question about programming layout

TJF1960

Active Member
Now that I have my feet wet with bitwise I have decided to completely revamp my code on all my running boards. I use the webcontrol boards to gather temp, IO data etc and send it to my ISY994. There is some coding for turning on/off outputs under certain conditions as well.
 
My question has to do with your preferences to coding. Do some of you prefer to have all the data gathering and control in the main loop then run a subroutine when its time to Webset or turn on/off an output, or do you prefer to have the data gathering and webset and control all contained in their respective subroutines which only runs when it is time to webset or switch an output? I am also looking at which consumes the least amount of resources, which is easier on the board - or does it really matter at all?
 
Thanks,
Tim
 
IMO it is preferable to code like you would in an object oriented language.  Group functional code together, use a few ram as general purpose registers, try not to use many short subroutines.  It should be easy to understand the code by quickly looking at it.
 
Until you start running out of available lines of code or memory resources you don't have to worry too much about structure.  Just keep the main loop as tight as possible and avoid blocking delays unless they are explicitly intended to pause the whole program.
 
A lot of agreement.
 
If I have a program with any significant amount of tasks, I really prefer to keep the main body simple and perform the various deeds in subroutines.  It makes editing a lot easier and it tends to be easier to add to the program or temporarily disable sections of code that way.  Even to the point where the main body just consecutively calls subroutines.  I think of it as modular programming.
 
And I hate DELAY.  I believe the code should always be running.  It is a crutch for weak programs in my opinion.  I only use it if I need a very very short delay between two lines of code.
 
Sounds like a plan to me. That was the direction I was headed but wanted to ask before I got to far into it.
Thank you both very much!
 
Back
Top