10 Automation coding best practices

 

This chapter covers

  • Building a full automation from start to finish
  • How to write and comment your code so others can understand it
  • Best practices around building robust and resumable automations

One of the biggest challenges most IT professionals face today is the speed at which things change. It used to be that you upgraded your operating systems and applications every three to five years. However, the subscription- and cloud-based models have drastically increased the frequency of upgrades. As a result, it is not uncommon to see multiple major upgrades in a single year now. One of the best ways to help yourself keep up with these trends is through automation. In this chapter, you will learn how you can ensure that your automations will grow with you by applying some best practices to your code.

Back in 2015, when Microsoft first released Windows 10, they introduced the concept of feature updates, where twice a year a new version of Windows is released. And this trend will continue with Windows 11. Even many Linux distros will have multiple versions. For instance, Ubuntu has some with long-term support (LTS) versions and some short-term support (STS) versions. Some distros have even moved to a continuous delivery model. All this means that you can end up with an assortment of different operating systems in your environment.

10.1 Defining the full automation

10.1.1 Structuring your automation

10.2 Converting a manual task to an automated one

10.3 Updating structured data

10.4 Using external tools

10.4.1 Finding installed applications

10.4.2 Call operators

10.5 Defining parameters

10.6 Making resumable automations

10.6.1 Determining code logic and functions

10.7 Waiting for automations

10.8 Think of the next person

10.8.1 Do not overcomplicate it

10.8.2 Comment, comment, comment