From 204032707e0ac89f9e68aa13220bd3452cac3873 Mon Sep 17 00:00:00 2001 From: Hong Zhang Date: Wed, 17 Jan 2018 16:36:40 -0800 Subject: [PATCH] Add a section to explain recommended default enum value. (#422) Signed-off-by: Hong Zhang --- STYLE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/STYLE.md b/STYLE.md index 94cffa23..aa739455 100644 --- a/STYLE.md +++ b/STYLE.md @@ -69,3 +69,9 @@ In addition, the following conventions should be followed: This is more efficient, extendable and self-describing. * To represent percentage values, use the Percent message type defined in [api/base.proto](api/base.proto). + +* For enum types, if one of the enum values is used for most cases, make it the + first enum value with `0` numeric value. Otherwise, define the first enum + value like `TYPE_NAME_UNSPECIFIED = 0`, and treat it as an error. This design + pattern forces developers to explicitly choose the correct enum value for + their use case, and avoid misunderstanding of the default behavior.