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

small-code-quality-improvements #3

Closed
wants to merge 2 commits into from
Closed

small-code-quality-improvements #3

wants to merge 2 commits into from

Conversation

TheRealHaui
Copy link

Made small code quality improvements.

@@ -412,7 +412,7 @@ private boolean isSorted() {
if (array == null) {
return true;
}
final boolean strict = isMinIncluded | isMaxIncluded;
final boolean strict = isMinIncluded || isMaxIncluded;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if the compiler were generating code verbatim, the use of | operator would be more efficient than || because a bitwise OR operation is faster than a jump on modern processor. But I guess that in practice, optimization done by the compiler results in the same assembly code in the end.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that astonished me due to the general known logical vs. bitwise stuff.
However, I've learned something and you're completely right -
http://javarevisited.blogspot.co.at/2015/01/difference-between-bitwsie-and-logical.html
Thank you!
I am going to undo this change.

if (versionGML.compareTo(LegacyNamespaces.VERSION_3_2_1) < 0) {
return FilterVersion.GML31;
}
if (versionGML != null && versionGML.compareTo(LegacyNamespaces.VERSION_3_2_1) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why this condition was keep in two separated if statement is because we currently check for only one version (GML 3.2.1), but we are likely to add new versions in the future. So the code may become something like:

if (version GML != null) {
    if (versionGML.compareTo(VERSION_3_2_1) < 0) do something
    if (versionGML.compareTo(VERSION_3_3) >= 0) do something else
    etc.
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to undo this too.

@@ -310,7 +310,6 @@ public void accept(final long sample) {
public void combine(final Statistics stats) {
ArgumentChecks.ensureNonNull("stats", stats);

// "if (a < b)" is equivalent to "if (!isNaN(a) && a < b)".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed unnecessary.
Therefore I removed it to increase readability.

Going to undo the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key element in the comment was the isNaN(a) part. Not so many developers are aware that (a < b) and !(a >= b) are not equivalent when using floating point numbers.

@@ -146,7 +146,6 @@ public WeakHashSet(final Class<E> type) {
@SuppressWarnings("unchecked")
@Workaround(library="JDK", version="1.7")
final Entry[] table = (Entry[]) Array.newInstance(Entry.class, MIN_CAPACITY);
// table = new Entry[size];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just before this comment, they were another comment explaining why we keep this comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that comment.
Going to undo.

@@ -464,6 +463,7 @@ public V put(final K key, final V value) throws NullArgumentException {
*
* @since 0.7
*/
@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case, this annotation can not be applied on a branch targeting JDK7.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, going to undo.

case 2: tail = parsedNames.get(1); break;
case 1: // fall through
case 0: throw new AssertionError(size);
default: tail = new DefaultScopedName(parsedNames.subList(1, size)); break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code had a logical ordering from highest value (where default stands for all values greater than 2) to zero.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it to be a small improvement due to https://sonarcloud.io/organizations/default/rules#rule_key=squid%3ASwitchLastCaseIsDefaultCheck

Going to undo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this switch the default is not for defensing programming, but is a case expected to be run in normal execution (actually most of the time for that switch statement).

@@ -571,6 +571,7 @@ public void logp(final Level level, final String sourceClass, final String sourc
*
* @since 0.5
*/
@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In those particular cases, this annotation can not be added on a code targeting JDK7 platform, because this method had been added in JDK8.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undoing.

asfgit pushed a commit that referenced this pull request Sep 25, 2017
@desruisseaux
Copy link
Contributor

Committed on 1f9c213

@TheRealHaui
Copy link
Author

Okay, just in that minute saw you've already commited the changes you accepted.
Thanks!

Shall I push further changes I consider to be improvements?

@TheRealHaui
Copy link
Author

Further changes I consider to be improvements general in the SIS project NOT in this pull request.

@desruisseaux
Copy link
Contributor

If you wish that would nice! But I propose that you do the patch against JDK8 branch instead of trunk. Also when doing tests, I suggest the following:

  • Focus more on the method contract instead than existing method behavior. For example having toString() to throw a NullPointerException is not part of method contract.
  • Verify if an existing test is already doing what you want to test. Try to identify what is new in the test you are adding. This is not necessarily a new method, but may be the context in which the method is invoked.
  • Avoid, if possible, to mix downstream functionalities in a test. For example ArrayEnvelopeTest should not use GeneralEnvelope or ImmutableEnvelope.
  • Choose variable names saying what the data are instead than their type. For example coordinate instead of doubleArray.

@asfgit asfgit closed this Jun 11, 2018
asfgit pushed a commit that referenced this pull request Sep 28, 2022
Because the workaround may introduce two categories with same name,
add a "#2", "#3", etc. suffix after duplicated names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants