Chapter 18. Professional-grade scripting

 

We’re almost ready to call you a professional toolmaker in PowerShell. Almost. Before you go around adding “PowerShell Toolmaker” to your resume, we think you should make certain that you’re exhibiting the behaviors and patterns of a true pro. With that in mind, this chapter is a list of the most common things to do and to avoid if you want to be seen as an upstanding, right-minded professional in the PowerShell world.

18.1. Using source control

Professionals worry about their code. They want it to last. They want it to survive them, should they move on to another organization. They want their code to be taken seriously, and they want to be able to recover if they make a mistake. That’s where source control—the subject of chapter 19—comes in.

A lot of people view source control the same way they do their tax forms. We mean, you’re supposed to file your taxes, right? But nobody likes to, and a few people don’t, so maybe it’s okay if I don’t. But source control in these modern times is pretty frictionless. The best tools (looking at you, VS Code) provide integration with some of the best source control options (Microsoft Team Foundation Server [TFS], Git, and so on), so working with source control isn’t much more difficult than pressing Ctrl-S to save your file and then pressing a key to commit those changes to source control.

18.2. Spelling it out

18.3. Commenting your code

18.4. Formatting your code

18.5. Using meaningful non-Hungarian variable names

18.6. Avoiding aliases

18.7. Avoiding awkward pipelines

18.8. Providing help

18.9. Avoiding Write-Host and Read-Host

18.10. Sticking with single quotes

18.11. Not polluting the global scope

18.12. Being flexible

18.13. Being secure

18.14. Striving for elegance

18.15. Summary