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

Refactoring (clean code) #164

Closed
wants to merge 20 commits into from
Closed

Conversation

ullenius
Copy link
Contributor

@ullenius ullenius commented Oct 30, 2019

Refactoring based on Clean Code (Uncle Bob) and Effective Java (Joshua Bloch):

  • Decoupling: Use List interface instead of ArrayList (SOLID principles, dependency inversion principle)
  • Returning empty List instead of null ("Return empty arrays or collections, not nulls", Effective Java)
  • Extracting magic String constants
  • Fixing invalid parameter ordering on a few assertEquals(expected, actual)
  • Removed a method parameter that was always constant (true). Thus useless
  • Other minor refactoring

* Reduces coupling (SOLID principles)
* Broke up assignment from method call
* Removing unused import
* Returning empty Collections instead of null (Effective Java, item mpatric#43)
* Removing unused method parameter
* Always override hashCode when overriding equals
if (obseleteFormat) {
return null;
return Collections.emptyList();
Copy link
Owner

Choose a reason for hiding this comment

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

Changing from returning null to returning an empty collection changes the SDK's interface, which might affect applications that are using it. I'd prefer not to make a breaking change unless it's absolutely neccessary.

Copy link
Contributor Author

@ullenius ullenius Nov 5, 2019

Choose a reason for hiding this comment

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

You have a valid point. I agree.

  • We should probably add a new test that checks that this method implementation returns a null-value. I presumed the tests would fail if breaking changes were made. They all passed.
  • Alternatively we could create a new implementation that returns an empty list and mark the old method as @Deprecated
  • Also ArrayList has the ensureCapacity() method which is not defined in the List interface. This could potentially break something (however unlikely).

Copy link
Contributor Author

@ullenius ullenius Nov 6, 2019

Choose a reason for hiding this comment

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

@mpatric Ended up with implementing a new interface that extends the old one, please see 202b0b0. This solution does not break existing code. Updated by 783020e

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably add a new test that checks that this method implementation returns a null-value. I presumed the tests would fail if breaking changes were made. They all passed.

Done. Please refer to bd77447

ullenius and others added 5 commits November 6, 2019 09:49
* Increased test coverage.
Replaced some home-brew implementations of hashCode/equals with more generic ones and made use of EqualsVerifier.

* Increased test coverage.
Replaced some home-brew implementations of hashCode/equals with more generic ones and made use of EqualsVerifier. (reverted from commit 580acf5)

* Increased code test coverage.
@coveralls
Copy link

coveralls commented Nov 6, 2019

Coverage Status

Coverage increased (+2.6%) to 71.139% when pulling ce12259 on ullenius:refactoring into c3917e8 on mpatric:master.

@@ -958,9 +958,22 @@ public void setUrl(String url) {
}

@Override
public List<ID3v2ChapterFrameData> getChapters() {
@Deprecated
Copy link
Contributor Author

@ullenius ullenius Nov 6, 2019

Choose a reason for hiding this comment

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

Rationale for deprecating this method is that it couples the return-type to an implementation. Thus encouraging bad coding practices.

References:
How and When to Deprecate APIs - Oracle's Java documentation

ullenius and others added 5 commits November 6, 2019 15:43
* Assert that getChapters returns null when using obsolete format
* Assert that getChapterTOC returns null when using obsolete format

* Assert that listOfChapters returns an empty list when using the obsolete
format
* Assert that listOfChapterTOC returns an empty list when using the obsolete
format
@hennr
Copy link
Collaborator

hennr commented Apr 12, 2022

This PR is quite old already and we didn't manage to agree on a version to merge until now.
Closing it for the time being. If someone wants to work on it again, please feel free to re-open.
Sorry and thanks for your work @ullenius

@hennr hennr closed this Apr 12, 2022
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.

5 participants