Add style guidance for k
prefix on constants.
The style guide only mentioned the `k` prefix for enums, but it is also used throughout Skia for constant values. Also removed guidance about using anonymous enums to declare an integral constant. static constexprs should be preferred here. Change-Id: I2f7d4d375cc914d4efb9fe60fbd90ddaaf8c1b69 No-Try: true Docs-Preview: https://skia.org/?cl=308919 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308919 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
parent
5dd3d8881c
commit
fb9f2e94ad
@ -83,7 +83,18 @@ int herdCats(const Array& cats) {
|
||||
}
|
||||
~~~~
|
||||
|
||||
Enum values are prefixed with k. Unscoped enum values are post fixed with
|
||||
Variables declared `constexpr` or `const`, and whose value is fixed for the
|
||||
duration of the program, are named with a leading "k" and then camel-capped.
|
||||
|
||||
<!--?prettify?-->
|
||||
~~~~
|
||||
int drawPicture() {
|
||||
constexpr SkISize kPictureSize = {100, 100};
|
||||
constexpr float kZoom = 1.0f;
|
||||
}
|
||||
~~~~
|
||||
|
||||
Enum values are also prefixed with k. Unscoped enum values are postfixed with
|
||||
an underscore and singular name of the enum name. The enum itself should be
|
||||
singular for exclusive values or plural for a bitfield. If a count is needed it
|
||||
is `k<singular enum name>Count` and not be a member of the enum (see example),
|
||||
@ -91,6 +102,7 @@ or a kLast member of the enum is fine too.
|
||||
|
||||
<!--?prettify?-->
|
||||
~~~~
|
||||
// Enum class does not need suffixes.
|
||||
enum class SkPancakeType {
|
||||
kBlueberry,
|
||||
kPlain,
|
||||
@ -100,29 +112,27 @@ enum class SkPancakeType {
|
||||
|
||||
<!--?prettify?-->
|
||||
~~~~
|
||||
enum SkPancakeType {
|
||||
kBlueberry_PancakeType,
|
||||
kPlain_PancakeType,
|
||||
kChocolateChip_PancakeType,
|
||||
// Enum should have a suffix after the enum name.
|
||||
enum SkDonutType {
|
||||
kGlazed_DonutType,
|
||||
kSprinkles_DonutType,
|
||||
kChocolate_DonutType,
|
||||
kMaple_DonutType,
|
||||
|
||||
kLast_PancakeType = kChocolateChip_PancakeType
|
||||
kLast_DonutType = kMaple_DonutType
|
||||
};
|
||||
|
||||
static const SkPancakeType kPancakeTypeCount = kLast_PancakeType + 1;
|
||||
static const SkDonutType kDonutTypeCount = kLast_DonutType + 1;
|
||||
~~~~
|
||||
|
||||
A bitfield:
|
||||
|
||||
<!--?prettify?-->
|
||||
~~~~
|
||||
enum SkSausageIngredientBits {
|
||||
kFennel_SuasageIngredientBit = 0x1,
|
||||
kFennel_SausageIngredientBit = 0x1,
|
||||
kBeef_SausageIngredientBit = 0x2
|
||||
};
|
||||
~~~~
|
||||
|
||||
or:
|
||||
|
||||
<!--?prettify?-->
|
||||
~~~~
|
||||
enum SkMatrixFlags {
|
||||
@ -131,13 +141,6 @@ enum SkMatrixFlags {
|
||||
};
|
||||
~~~~
|
||||
|
||||
Exception: anonymous enums can be used to declare integral constants, e.g.:
|
||||
|
||||
<!--?prettify?-->
|
||||
~~~~
|
||||
enum { kFavoriteNumber = 7 };
|
||||
~~~~
|
||||
|
||||
Macros are all caps with underscores between words. Macros that have greater
|
||||
than file scope should be prefixed SK or GR.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user