Skip to content
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

RFC: Standardize curly bracket style #24

Open
sanine-a opened this issue Feb 17, 2021 · 4 comments
Open

RFC: Standardize curly bracket style #24

sanine-a opened this issue Feb 17, 2021 · 4 comments
Labels
question Further information is requested

Comments

@sanine-a
Copy link
Member

This came up in our discussion of #23, and I think we should try to standardize. Do we want to use brackets on separate lines?

void func()
{
    // do something
}

Or do we want to use brackets on the same line?

void func() {
    // do something
}

My preference is the first one, because I think it helps to visually distinguish function declarations from code blocks and aid somewhat in code navigation, and it also can make certain types of formatting a bit nicer. For instance, if a function has many arguments, it can help to break those arguments up over multiple lines, and I think that looks kind of strange if the brackets are on the same line as the parentheses. However, it's only a preference and if others feel very strongly about using brackets on the same line I'd be fine with that.

@sanine-a sanine-a added the question Further information is requested label Feb 17, 2021
@bryankennedy
Copy link
Member

I am not up to speed on C++ standards, but I will say that at SMM we've tried to defer to other people's code style guides rather than develop our own. I'd suggest we pick and existing standard and if we feel very strongly that we need to make an exception, we can document our deviation from that style.

For JS we use Airbnb's because they're the leader in that space.

My quick search seems to suggest that Google's standards are the leader in the C++ space. Here is their guidance on function declarations, which I think is what you're discussing here on curly braces.

@bryankennedy
Copy link
Member

And this tool (cpplint), looks like it would make it very easy to automatically lint our code based on that style guide.

@eojreyem
Copy link
Contributor

eojreyem commented Feb 17, 2021

Thanks for creating a space for this dialog @sanine-a and weighing in.

I had similar observations to @twsdbailey , that most arduino libraries I've seen are same line. Same line is how I was writing prior to using the defaults of a VS Code linter. Looking at @bryankennedy links it seems that is also what Google is doing.I think we should move forward with the Same Line example. I'll dig into cpplint

@brandonwkipp
Copy link
Contributor

Fwiw, @eojreyem and I have linters built into our editors (vscode) to handle linting. When this issue first came up, @eojreyem discovered we could change our clang format style to use the "Google" format and after doing so, put the curly bracket on the line. After reading the link @bryankennedy shared, I'm in favor of using Google's style guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

4 participants