How to turn repeating code into a function
A function is a named section of code, a piece of code within a script or program that is given a label, and may be used by referring to the label. This is a very common programming paradigm and appears in most imperative programming languages. Some languages, such as PowerShell and Python, call these pieces of code functions. Some call them subroutines, subprograms, methods, or procedures. The paradigm is called procedural programming and lies between the scripting that most people practice with PowerShell and full object-oriented programming in languages such as C++ and Java. Functional programming is a different paradigm, with a declarative style.
Imperative, Declarative, Procedural, and Functional
I’m throwing around a lot of new words here, so it’s worth quickly explaining what they mean.
Imperative languages are recipe languages such as Python and PowerShell. Each step in the script or program tells the computer...