Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Avoiding unnecessary use of "final"

Hi,

Context: https://git.eclipse.org/r/c/122605/

https://gerrit-review.googlesource.com/Documentation/dev-contributing.html#style contains:

When to use `final` modifier and when not (in new code):

Always:

  * final fields: marking fields as final forces them to be
  initialized in the constructor or at declaration
  * final static fields: clearly communicates the intent
  * to use final variables in inner anonymous classes

Optional:

  * final classes: use when appropriate, e.g. API restriction
  * final methods: similar to final classes

Never:

  * local variables: it clutters the code, and makes the code less
  readable. When copying old code to new location, finals should
  be removed
  * method parameters: similar to local variables

I'm enough used to this that I had assumed JGit uses the same style, but now that I check https://wiki.eclipse.org/EGit/Contributor_Guide#Coding_standards I don't see it. I would like to propose we adopt the same standards.

Objections? Are there tools that can update older parts of the codebase that overuse 'final' (just like older parts of Gerrit did)? Other thoughts?

Thanks,
Jonathan

Back to the top