9
Don’t Repeat Yourself – Functions and Scriptblocks
In this chapter, we’re going to look at one of the basic principles of software development and learn how to apply it to save ourselves effort and make our code easier to maintain: Don’t Repeat Yourself, also known as the DRY principle. In The Pragmatic Programmer, by Andy Hunt and Dave Thomas, the principle is stated as “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” Some programmers will take this principle to its logical conclusion and have no repeating code anywhere. We’re writing scripts, and so we will apply the principle just as much as is convenient. We will talk about the concept of functions within code. By the end of the ...
Get PowerShell 7 Workshop now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.