Skip to main content

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

On Mon, May 14, 2018 at 11:59 PM, Jonathan Nieder <jrn@xxxxxxxxxx> wrote:
Hi,



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.

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


Doesn't Han-Wen's change already remove those ?

-Matthias

Back to the top