Why Coding Standards and Best Practices are Important?
What is Coding Standard?
Coding best practices are a set of informal rules that helps improve the quality of a product irrespective of the technology. RPA is an emerging technology and robots gonna be used for far longer than original developer ever envisaged; so any rules need to facilitate, both initial development and subsequent maintenance and enhancement by people other than the original programmer.
Now, the question is why should we follow best practices?
"If you put your heart and your soul into your work, It will be the best work ever."
When we learn a new technology, rather than following its best practices, we usually begin to code in our own style instead. Mostly, we write the code in a style we want, not even that has been suggested to us. Once we start to code using our own style, like a spoken language dialect, it will become second nature - We will use it in everything we develop. Another problem, If you come back to the code after a few days or months, you will not be able to work out what's happening.
What best practices should be followed ?
- Readable : If you follow coding standards, your code will be readable, both to you and others. Now, it might not be the best standard, but at least, in a short period of time, you will be able to follow the flow. Whether it is the naming convention or self explanatory comments or intent of your code is easier to follow. Examples of naming convention is as follows :
- Variables : userId, userName, applicationPassword etc.
- Workflow / Function / Class / Sequence : OpenApplication, InitilizeProcess, GetTransaction, CloseApplication etc.
Image 1 : Example of a well maintained and easily readable workflow
- Collaborate working on separate file : If your code is not easily readable, it would be harder to collaborate on, why ? If it's hard for one person to work on a code base without wondering where errors might turn up, extrapolate it over a team of more than one person. Therefore, keep your code clean and break the whole process in smaller and easily maintable workflows.
- Exception Handling : An exception is a problem that occurs during the execution of a program. When an exception occurs, the normal flow of the program would be disrupted and the program would be terminated abnormally, which is not recommended, just to avoid such problem below exception handling techniques should be followed :
- Always keep your code inside in a try catch block
- Use auto recovery / retry
- Implement flow decisions and if else conditions
- Time and Sync Issues (i.e. Wait for elements to appear in case of any kind of application / network slowness or delay)
- Real time process logging
Image 2 : Example for a Try-Catch block
- Back up your code daily : Enough said. Dead battery, blackout, software glitch, fire, nuclear disaster – all of these may result in loss of data. Making sure you save daily and back up your workflow on TFS / SVN is a simple way to ensure that your code stays safe. Also, do not forget to maintain the versioning that helps keep your robot running in case of any issues in the updated version.
Image 3 : Connect workflow with source controlling (i.e. TFS or SVN)
Image 4 : Showing categorized view of some other Best Practices
Coding standards and best practices is a huge topic – one that can go on for many pages. Application of these standards and practices also varies by application – whether you are working on a huge corporate RPA project or helping yourself learning a new tool. Based on many factors, it is ultimately up to you to make sure that the code you develop is good robot.
Thanks @Vikas Kulhari