drbitboy
Lifetime Supporting Member
Summary
Where is the break between doing something brute force vs. using things like loops? I realize that the fixed fractional overhead of loops will sometimes be a deal-breaker, but I suspect that is rarely an issue in modern systems, so I'd like to frame the question to ignore cases where only brute force works as they already have an answer.
Thank you.
Details
Example from thread https://www.plctalk.net/qanda/showthread.php?t=124937, PDF here: https://www.plctalk.net/qanda/attachment.php?attachmentid=54442&d=1589929214
In [LAD 10] there are 31 rungs that set all of the step bits i.e.
I am looking for opinions: at what point would you put that into a loop?
Musings, TL;DR
I am naturally attracted to the more "elegant" approaches: if the computer was not invented to do repetitive stuff then why are we using it; I prefer pieces of code that use up less vertical real-estate on the screen. Also, doing housekeeping in a loop makes it easure (usually) to add steps when needed, and makes the process less error-prone. However, those are self- and coder-centered points of view, and I recognize that it can obfuscate the code down the road to a maintenance tech and even often myself, and it's harder to debug. So this could be framed as a trade-off between coder time and user time, or between capital investment and operational expenses.
Where is the break between doing something brute force vs. using things like loops? I realize that the fixed fractional overhead of loops will sometimes be a deal-breaker, but I suspect that is rarely an issue in modern systems, so I'd like to frame the question to ignore cases where only brute force works as they already have an answer.
Thank you.
Details
Example from thread https://www.plctalk.net/qanda/showthread.php?t=124937, PDF here: https://www.plctalk.net/qanda/attachment.php?attachmentid=54442&d=1589929214
In [LAD 10] there are 31 rungs that set all of the step bits i.e.
Code:
EQU C5:0.ACC 0 OTE B3:0/0
Musings, TL;DR
I am naturally attracted to the more "elegant" approaches: if the computer was not invented to do repetitive stuff then why are we using it; I prefer pieces of code that use up less vertical real-estate on the screen. Also, doing housekeeping in a loop makes it easure (usually) to add steps when needed, and makes the process less error-prone. However, those are self- and coder-centered points of view, and I recognize that it can obfuscate the code down the road to a maintenance tech and even often myself, and it's harder to debug. So this could be framed as a trade-off between coder time and user time, or between capital investment and operational expenses.