When was the last time you reviewed your code? In this Tune Up post, we give you a few tips you can follow to clean up your code and keep it that way.
Reviewing and cleaning up your code is never something that is on the top of your to-do list. Having clean code can decrease the amount of time spent troubleshooting your system, as well as the time spent on future developments and training new team members. Here are some of our favorite ways to keep your code squeaky clean!
#1 - Remove What is Unnecessary
Change is a common element within the manufacturing world. This change is often captured in the logic right away, but the clean-up may be left for a later date. Leaving this un-used logic in can start to bog down the system and could potentially confuse future troubleshooters.
The easiest first step in cleaning up unnecessary code is to remove any unused or duplicate tags. Removing these unused tags will not only clean up some space but it will also prevent you from using incorrect tag names in the future.
Having forced signals can be risky since they are not always saved should something go wrong with your PLC. Check your system and determine if your forces are needed or if they are legacy items. If these cannot be removed, instead create a section of logic for your forces. This way you can keep track of the forces in your system easily and you don’t risk losing them should the PLC restart.
Finally, remove any unneeded or legacy logic. Be sure to consult with your team before deleting anything though, as it might be used elsewhere. Removing this logic will save you time on troubleshooting and training new employees.
#2 - Update Your Tags
Tag names don’t get the respect that they deserve. Clean, descriptive tag names provide all the information you need, no matter what section of the logic you are in. If you have a section that controls a pump and you have a low speed fault tag, PumpM3_LowSpdFlt would be more descriptive than Pump_Alarm1.
If you have a lot of tags in your code, sitting down and renaming them all may seem like an impossible task. Start with something you have worked on recently. Go through and review the tag names in this section and ask yourself, does this tag describe what it affects and what it does?
Continue tackling each section, focusing on the most used ones first. Soon you will have made your way through and updated the tags for the whole system – just make sure you document as you go so when you come back to it, you know what's been done.
#3 - Add More Comments!
The better your logic is documented, the easier it is to troubleshoot. It is especially important to document how it was supposed to function rather than just what the logic does functionally. This helps future programmers decide how best to modify logic under new conditions and should minimize the amount of zombie logic that will accumulate in your PLC.
Start by finding a section of logic that you have a hard time understanding. By tackling a complex or unknown section, it allows you to determine what points of the logic you have a hard time understanding and what comments would help explain this section.
This first section may take you a bit longer to complete since you have to decipher it yourself, but you will come out having a better understanding and strategy for the remaining sections.
At first, cleaning up your code can seem daunting and like a waste of time. However, by pruning the unnecessary, updating your tags and adding more comments, you will find that you no longer run into the same confusions over and over while troubleshooting.
And who knows, maybe the next time you need to clean your code, you'll find there are less cobwebs than there used to be.
What are your code clean-up tips? Reach out and let us know at info@JordanSynergist.com!