mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Proposal: Property naming in C++ (#720)
This proposed style change allows C++ classes in the Carbon project to provide methods that are named like variables, so long as they behave like _properties_ of the class. It also requires data member names to have a trailing `_`. Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Chandler Carruth
parent
532948d9a5
commit
bf49f2efed
@@ -54,16 +54,22 @@ serves to simplify it.
|
||||
|
||||
- Known, compile-time constants use `UpperCamelCase`, referencing Proper
|
||||
Nouns.
|
||||
- This includes namespaces, type names, functions, member functions,
|
||||
template parameters, `constexpr` variables, enumerators, etc.
|
||||
- This includes namespaces, type names, functions, member functions
|
||||
(except as noted below), template parameters, `constexpr` variables,
|
||||
enumerators, etc.
|
||||
- Note that virtual member functions should be named with
|
||||
`UpperCamelCase`. The distinction between a virtual function and a
|
||||
non-virtual function should be invisible, especially at the call site,
|
||||
as that is an internal implementation detail. We want to be able to
|
||||
freely change that without updating the name.
|
||||
- Member functions may use `snake_case` names if they do nothing besides
|
||||
return a reference to a data member (or assign a value to a data member, in
|
||||
the case of `set_` methods), **or** if their behavior (including
|
||||
performance) would be unsurprising to a caller who assumes they are
|
||||
implemented that way.
|
||||
- All other names use `snake_case`, including function parameters, and
|
||||
non-constant local and member variables.
|
||||
- Notably, don't use the `_` suffix for member variable names.
|
||||
- Private member variables should have a trailing `_`.
|
||||
|
||||
### File names
|
||||
|
||||
|
||||
Reference in New Issue
Block a user