Skip to content

Added examples of Opening / closing braces #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 11, 2018
Merged

Conversation

1RedOne
Copy link
Contributor

@1RedOne 1RedOne commented Oct 2, 2018

Seemed like the life of this discussion issue has concluded, #24, so lets include the agreed upon examples inside the docs :)

Seemed like the life of this discussion issue has concluded, PoshCode#24, so lets include the agreed upon examples inside the docs :)
````
function Get-Noun {
end {
if($Wide) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a space after the if.

@Jaykul
Copy link
Member

Jaykul commented Oct 3, 2018

You're kind-of working from the wrong story. I closed #24 because we opened #81 after GitHub added voting by 👍 or 👎 ...

However, the code sample you've used is fine, it matches the One True Brace Style (aka 1TBS or OTBS) that won the voting with a more than 5-to-3 margin over the closest alternative, and the discussion in #81 has also come to it's natural end 😉

The headline, however, should say that we recommend following the One True Brace Style, which puts both opening and closing braces on the same line so that new lines of code can be inserted between any two lines with no risk of accidentally breaking the code by separating braces from their statement blocks.

You could use part of the explanation from that post about the history: this style really won in the PowerShell community partly because the style is one of two used in C languages --it's a variant of the K&R (Kernighan and Ritchie) style from their book The C Programming Language-- but also because for the first few years of PowerShell's existence, this was the only style that could be typed at the command line.

Personally, I think it would be great to remind people here that although this is the style that most of the community uses at this time, there's no reason why you can't choose to use another style for your company, or for your project -- but you should really pick one of the big three (OTBS, Allman, Stroustrup) and specify which one in your ReadMe.md or Contributing.md guide.

@@ -82,12 +82,21 @@ end{}
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.

#### Open braces on the same line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

Follow the one-true-brace style.

Open braces always go on the same line

...

Close braces start a new line ... but follow-on statements like else stay on that line.

}
}
}
````
#### Closing braces always on their own line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on their own line. They start a new line.

#### Closing braces always on their own line
Because that's how they're supposed to be!
(TODO: This is in discussion in [#24](https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/24))
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to say "the community recommends following the One True Brace Style (OTBS)"

Closing braces don't go on their own line. It needs to say we recommend... starting a new line with your closing brace

And it should include that bit about "so that new lines of code can be inserted between any two lines"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@1RedOne
Copy link
Contributor Author

1RedOne commented Oct 3, 2018

Excellent feedback, Joel. I implemented it, the tidbit about the origin of the style (with a wiki link) and then reiterated that these are guidelines, not rules.

@Jaykul Jaykul merged commit d61c67d into PoshCode:master Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants