Skip to content

Commit 58dffb7

Browse files
authored
Added examples of Opening / closing braces
Seemed like the life of this discussion issue has concluded, PoshCode#24, so lets include the agreed upon examples inside the docs :)
1 parent 839e032 commit 58dffb7

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Style-Guide/Code-Layout-and-Formatting.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,21 @@ end{}
8282
You can always delete or ignore one of the blocks (or add the `begin` block), add parameters and so on, but you should avoid writing scripts or functions without CmdletBinding, and you should always at least _consider_ making it take pipeline input.
8383

8484
#### Open braces on the same line
85-
Code folding is nicer in many editors.
86-
(TODO: This is in discussion in [#24](https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/24))
87-
85+
Code folding is nicer in many editors when a scriptblock is placed on the end of the same line, as in this example.
86+
87+
````
88+
function Get-Noun {
89+
end {
90+
if($Wide) {
91+
Get-Command | Sort-Object Noun -Unique | Format-Wide Noun
92+
} else {
93+
Get-Command | Sort-Object Noun -Unique | Select-Object -Expand Noun
94+
}
95+
}
96+
}
97+
````
8898
#### Closing braces always on their own line
89-
Because that's how they're supposed to be!
90-
(TODO: This is in discussion in [#24](https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/24))
99+
Note the above example again, community guidelines recommend placing your closing braces on their own line. This practice makes it easier to pair up matching opening and closing braces when looking to see where a particular scriptblock ends.
91100

92101
#### Prefer: param() begin, process, end
93102
That's the order PowerShell will execute it in

0 commit comments

Comments
 (0)