Naming conventions

You should always try to follow common naming conventions, to make longer code easier to understand. By using distinct capitalization for parameters and variables, you can immediately see whether a variable used in a longer piece of code is a parameter, or whether it has been declared somewhere in your code. The following table explains the different capitalization types that are commonly used in PowerShell:

CamelCase

Function parameters, public properties of a PowerShell class, cmdlet nouns

pascalCase

Variables declared in code, private properties of a PowerShell class

lowercase

PowerShell operators (-in, -like), language keywords (for, foreach)

UPPERCASE

Comment-based help parameters (.SYNOPSIS, .NOTES)

 

We commonly use pascalCase and CamelCase to distinguish variables from parameters. Developers in .NET have adopted the same convention for naming their public fields (public properties of a class) and private fields:

Properly using cases is one thing; the other is to give your variables a proper name. Unless it is absolutely unavoidable, values should not simply appear out of thin air. If they are parameters or constants, they should be declared beforehand.

There are actual scripts out there that look like the following example:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset