Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear rational in ExplicitInitialization #6472

Closed
Vampire opened this issue Feb 24, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@Vampire
Copy link
Contributor

commented Feb 24, 2019

The rational says

Rationale: Each instance variable gets initialized twice, to the same value. Java initializes each instance variable to its default value (0 or null) before performing any initialization specified in the code. So in this case, x gets initialized to 0 twice, and bar gets initialized to null twice. So there is a minor inefficiency. This style of coding is a holdover from C/C++ style coding, and it shows that the developer isn't really confident that Java initializes instance variables to default values.

Issues:

  • x is referenced but the example that is referenced is not present
  • bar is referenced but the example that is referenced is not present
  • This style of coding is a holdover from C/C++ style coding, and it shows that the developer isn't really confident that Java initializes instance variables to default values. is very negative and also wrong. I agree that explicit initialization should be left out if default is fine, but there are style guides that say that initialization should always be done explicitly. This is not necessarily a leftover from C/C++ style coding or inconfidence of the developer. The rational to have it is, that it is clear from looking at it to what it is initialized without the need to think about it. This is the same as for example int x = arr[y++] = y;. This construct could either be seen as "wow, this developer knows exactly what the JVM is doing and in which order it evaluates expression parts", or it can be seen as "what the fuck, this is unreadable, I need to think 30 minutes about what happens in this statement each time I stumble upon it". For this example I would prefer not using such a wonky construct that 90% of the developers will not instantly understand correctly even if it would show my excellence in understanding JVM internals.
@romani

This comment has been minimized.

Copy link
Member

commented Feb 24, 2019

@Vampire , all such text is in src/xdoc folder, please send PR with change, for all approved issues.

@romani romani added the approved label Feb 24, 2019

Vampire added a commit to Vampire/checkstyle that referenced this issue Mar 7, 2019

@romani romani closed this in #6522 Mar 8, 2019

romani added a commit that referenced this issue Mar 8, 2019

@romani romani added the miscellaneous label Mar 8, 2019

@romani romani added this to the 8.19 milestone Mar 8, 2019

Vantuz added a commit to Vantuz/checkstyle that referenced this issue Apr 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.