From 76e10c5102cb8438ef31289398ade1a6cdf4f0e5 Mon Sep 17 00:00:00 2001 From: John Watson Date: Tue, 15 Dec 2020 18:21:16 -0800 Subject: [PATCH] CONTRIBUTING.md update with some more best practices. (#2301) * add a section on class member ordering, since it's not covered in the google style guide * add an item about toString methods * add a note about final fields coming before non-final --- CONTRIBUTING.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 16411eb8061..1cb0e706116 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,6 +67,15 @@ which uses [google-java-format](https://github.com/google/google-java-format) li * By default, all arguments/members are treated as non-null. Every argument/member that can be `null` must be annotated with `@Nullable`. * The project aims to provide a consistent experience across all the public APIs. It is important to ensure consistency (same look and feel) across different public packages. * Use `final` for public classes everywhere it is possible, this ensures that these classes cannot be extended when the API does not intend to offer that functionality. +* In general, we use the following ordering of class members: + * static fields (final before non-final) + * non-static fields (final before non-final) + * constructors + * static methods + * instance methods + * inner classes +* Adding `toString()` overrides on classes is encouraged, but we only use `toString()` to provide debugging assistance. The implementations +of all `toString()` methods should be considered to be unstable unless explicitly documented otherwise. If you notice any practice being applied in the project consistently that isn't listed here, please consider a pull request to add it.