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

Document C++ code style and naming conventions #4685

Open
Xrayez opened this issue Feb 26, 2021 · 1 comment
Open

Document C++ code style and naming conventions #4685

Xrayez opened this issue Feb 26, 2021 · 1 comment
Labels
area:contributing Issues and PRs related to the Contributing/Development section of the documentation enhancement

Comments

@Xrayez
Copy link
Contributor

Xrayez commented Feb 26, 2021

Your Godot version:
Any.

Issue description:
There's little information regarding existing code style used throughout Godot's C++ codebase in the docs, unlike GDScript and C#. This is important to document to ensure Godot follows consistent code style, and especially important for new contributors.

See godotengine/godot#33027 for consensus regarding C++ code style in Godot. To summarize:

Formatting

  • No empty line after opening brace (enforced by clang-format).
  • One line between function implementations (no tools found yet).
  • Use braces on single-statement if / else blocks (might be doable with clang-tidy).
  • No short case labels on a single line (can be enforced by clang-format).
  • Switch/case use of brackets (undecided).

Code style

  • snake_case for identifiers (variables).
  • PascalCase for classes.
  • SHOUTING_SNAKE_CASE for constants.
  • Use p_ for method parameters, and r_ for parameters which are intended to "return" something (modified by the method).
  • Naming of boolean setters/getters (no consensus yet, see Naming of boolean setters/getters godot#33026).

URL to the documentation page (if already existing):
Can be added to the "Code style guidelines" page.

@skyace65 skyace65 added the area:contributing Issues and PRs related to the Contributing/Development section of the documentation label Dec 28, 2022
@romlok
Copy link
Contributor

romlok commented Aug 17, 2023

It should also be noted that m_ is seemingly the preferred prefix for macro parameters. p_ and r_ are mentioned in the docs (though not in the coding style doc), but searching for m_ comes up blank.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:contributing Issues and PRs related to the Contributing/Development section of the documentation enhancement
Projects
None yet
Development

No branches or pull requests

3 participants