PowerShell is far more forgiving than most scripting and programming languages. Some languages will generate errors if you have a single space by itself on an otherwise blank line, but with PowerShell, you can have code formatted like this (this is stolen from the Collections Hands-On article, but with the formatting absolutely destroyed):
And at the same time, you could format that exact same command as a single line, like this:
So don't be too worried if an example you find here or elsewhere online looks different -- spacing barely matters at all in PowerShell.
You'll sometimes see lines entered with the equals sign all aligned, like this:
This can actually help tremendously when your scripts get long enough to become difficult to parse at a glance.
If you're just plain sloppy with code, however, there are tools built into most editors you can use. For instance, in Visual Studio Code, you can use a keyboard shortcut to format your code. In Windows, if you press Shift + Alt + F, you can turn this bit of sloppy code:
...into this:
As Visual Studio Code (not to be confused with Visual Studio!) is pretty close to being an industry standard, it's a good idea to get yourself acquainted with it. It's not just good for PowerShell - thanks to its extensible nature, you can comfortably write in any language you wish.
A very important part of easy-to-follow code is good commenting. As your functions get more and more complicated, even good formatting can let you down when you need to find something very specific.
Comments are lines in your code that, well, aren't code. They can say anything you want, really, but mostly should be used as a way to remind yourself of why you did something, where you can find a definition for a function, or just a way to say "please fix this later" when you know you did something very sloppily.
In PowerShell, you can insert comments one of two ways.
A single line comment begin with a hash character (#) - these are useful for quick, short
comments. These can be used at the end of a line, but anything that comes after one of these on a single
line will be commented out. These can also be used for bug-testing if you think a single line is causing you
an issue - just pop one at the beginning of a line and none of the code after it will proceed.
A block comment begins with <# and ends with #>. Unlike single-line
comments, a block comment, once started, will just keep on going until you close it out. It's mostly used
for more in-depth descriptions of how to use a function or command. However, it can also be used to comment
things out inline with other code.
You'll see pretty heavy use of comments in example code in upcoming tutorials - it's an easy way to keep some notes along with your work, and a little reminder to why you did whatever weird thing you did last month might save you a lot of trouble when trying to decipher your own handiwork later on.
In this tutorial, we should have picked up a few pointers.