diff --git a/site/dev/contrib/style.md b/site/dev/contrib/style.md index 2a695c049d..5ef7aec9fe 100644 --- a/site/dev/contrib/style.md +++ b/site/dev/contrib/style.md @@ -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. + + +~~~~ +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 `kCount` and not be a member of the enum (see example), @@ -91,6 +102,7 @@ or a kLast member of the enum is fine too. ~~~~ +// Enum class does not need suffixes. enum class SkPancakeType { kBlueberry, kPlain, @@ -100,29 +112,27 @@ enum class SkPancakeType { ~~~~ -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: - ~~~~ enum SkSausageIngredientBits { - kFennel_SuasageIngredientBit = 0x1, + kFennel_SausageIngredientBit = 0x1, kBeef_SausageIngredientBit = 0x2 }; ~~~~ -or: - ~~~~ enum SkMatrixFlags { @@ -131,13 +141,6 @@ enum SkMatrixFlags { }; ~~~~ -Exception: anonymous enums can be used to declare integral constants, e.g.: - - -~~~~ -enum { kFavoriteNumber = 7 }; -~~~~ - Macros are all caps with underscores between words. Macros that have greater than file scope should be prefixed SK or GR.