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

Addressbook::addTag() is not used #169 #179

Merged
merged 5 commits into from
Feb 20, 2017

Conversation

PierceAndy
Copy link
Contributor

@PierceAndy PierceAndy commented Feb 10, 2017

Fixes #169

Removed unused tag level methods in AddressBook:

  • addTag()
  • removeTag()
  • containsTag()

@yamgent @chao1995 With your unit test experiences, what are your thoughts on how tests that relied on containsTag() were handled?

@PierceAndy PierceAndy self-assigned this Feb 10, 2017
@mention-bot
Copy link

@PierceAndy, thanks for your PR! By analyzing the history of the files in this pull request, we identified @YijinL, @thenaesh and @yamgent to be potential reviewers.

@CanIHasReview-bot
Copy link

v1

@PierceAndy submitted v1 for review.

(📚 Archive)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level2.git refs/pr/179/1/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

[v1 1/3]

commands that support the addition of Tags only; is not part of any
learning objectives; and AddressBook#syncTagsWithMasterList() already
handles the addition of Tags from a Person gracefully without using
exceptions.

Not a grammar guru, but it seems weird to use semi-colons here instead of commas
and a fullstop. Perhaps it is because of the missing subject and the use of and?

Maybe something like this might read a bit better:

commands that support the addition of Tags only. It is not part of any
learning objectives, and AddressBook#syncTagsWithMasterList()...

*
* @throws DuplicateTagException if the Tag to add is a duplicate of an existing Tag in the list.
*/
public void add(Tag toAdd) throws DuplicateTagException {
Copy link
Member

Choose a reason for hiding this comment

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

Nice spot, but this should probably be in a separate commit because [v1 1/3] is about AddressBook#addTag(), not UniqueTagList#add().

Also, not sure whether it is a good reason to remove UniqueTagList#add() just because AddressBook#addTag() no longer exist, since I can understand that you are not supposed to manipulate AddressBook's tags directly, but I don't expect UniqueTagList to no longer allow adding new tags as a result. @chao1995 Your thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AddressBook#addTag() is the only method that uses UniqueTagList#add(), and similarly so with remove in [v1 2/3]. Of course, I can understand the arguments for having a separate issue + PR for unused methods in UniqueTagList.

Copy link
Member

Choose a reason for hiding this comment

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

Actually I meant having a separate commit in this current PR, not a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

this should probably be in a separate commit

Agree.

whether it is a good reason to remove UniqueTagList#add() just because AddressBook#addTag() no longer exist

Since UniqueTagList#add() is never used as well. I would suggest we remove it.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

[v1 2/3]

*
* @throws TagNotFoundException if no such Tag could be found in the list.
*/
public void remove(Tag toRemove) throws TagNotFoundException {
Copy link
Member

Choose a reason for hiding this comment

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

Same concern as [v1 1/3].

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

[v1 3/3]

assertFalse(defaultAddressBook.containsTag(tagEconomist));
assertFalse(defaultAddressBook.containsTag(tagPrizeWinner));
assertFalse(defaultAddressBook.getAllTags().contains(tagEconomist));
assertFalse(defaultAddressBook.getAllTags().contains(tagPrizeWinner));
Copy link
Member

Choose a reason for hiding this comment

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

@PierceAndy I assume that you are talking about this one in the OP of the PR.

Since containsTag() is only used in testing, and we are removing it, this alternative looks acceptable. However, it seems that we also have a method AddressBookTest#isTagObjectInAddressBookList() that also allow us to check the tags in the AddressBook (like how it used in line 100). Maybe consider using that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it does make sense to use that and be consistent.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

Changes requested (as above)

EDIT: I edited my review regarding the commit message to make it more clear (and also removed an irrelevant part).

@PierceAndy
Copy link
Contributor Author

@yamgent About the use of semi-colons, yes it's possible to use semi-colons in place of commas as a kind of "super-comma" when your list is complex. As to whether it's good practice, I guess I might reconsider it.

Copy link
Contributor

@chao1995 chao1995 left a comment

Choose a reason for hiding this comment

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

No additional comment. Can proceed to next iteration.

@CanIHasReview-bot
Copy link

v2

@PierceAndy submitted v2 for review.

(📚 Archive) (📈 Interdiff between v1 and v2)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level2.git refs/pr/179/2/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@PierceAndy
Copy link
Contributor Author

v2

  • Split UniqueTagList changes into their own commits
  • Replaced uses of AddressBook#getAllTags() + UniqueTagList#contains() in AddressBookTest with AddressBookTest#isTagObjectInAddressBookList()
  • Reworded commit messages based on feedback.

@CanIHasReview-bot
Copy link

v3

@PierceAndy submitted v3 for review.

(📚 Archive) (📈 Interdiff between v2 and v3)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level2.git refs/pr/179/3/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@PierceAndy
Copy link
Contributor Author

v3

@yamgent @chao1995

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

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

Ok, they do look better with the new flow.

Copy link
Contributor

@chao1995 chao1995 left a comment

Choose a reason for hiding this comment

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

LGTM.

@PierceAndy
Copy link
Contributor Author

This PR has two approved peer reviews. Proceeding with next round of reviews with senior dev.
Attn: @damithc

Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

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

Looks like tests are missing some verifications, but unrelated to this PR. Probably need to fix separately. Create an issue?

defaultAddressBook.addPerson(davidElliot);
assertTrue(defaultAddressBook.containsTag(tagEconomist));
assertTrue(defaultAddressBook.containsTag(tagPrizeWinner));

Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed something odd here. The test does not confirm that the person is added correctly.

@pyokagan
Copy link
Contributor

Just a side note: I just realised that AddressBookTest#isTagObjectInAddressBookList() isn't actually a 1-to-1 replacement of AddressBook#containsTag(). The former checks for equal references while the latter checks for equal values.

@damithc
Copy link
Contributor

damithc commented Feb 14, 2017

Just a side note: I just realised that AddressBookTest#isTagObjectInAddressBookList() isn't actually a 1-to-1 replacement of AddressBook#containsTag(). The former checks for equal references while the latter checks for equal values.

Oh yes. That was why the method was added in the first place (to confirm the Person object points to Tag objects in the common tag list instead of keeping it's own copies of the tags). Probably need better method name and better header comment to emphasize this 'special' nature of the method. That also means the method is specific to testing and it has to exist with or without AddressBook#containsTag().

@pyokagan
Copy link
Contributor

pyokagan commented Feb 14, 2017

@damithc

That also means the method is specific to testing and it has to exist with or without AddressBook#containsTag().

Yes, agreed. In light of this new discovery information (which should be emphasized in the commit message), I agree that AddressBookTest#isTagObjectInAddressBookList() should stay inside the test code, and that we can remove AddressBook#containsTag(). (The alternative would be to make AddressBook#containsTag() compare by reference to fully take over the responsibilities of AddressBookTest#isTagObjectInAddressBookList(), but that would be hugely inconsistent with our API design.)

Copy link
Contributor

@pyokagan pyokagan left a comment

Choose a reason for hiding this comment

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

[v3 5/5]

AddressBook: remove unused containsTag()

AddressBook#containsTag() checks if a given Tag is in the master list of
Tags.

This method is not used anywhere, and can be classified as unused code.
There are no commands that support it, and it is also not part of any
learning objectives. While it is used in two tests for
AddressBook#addPerson(), it should be replaced with the existing
AddressBookTest#isTagObjectInAddressBookList() to improve code reuse.

So this is misleading -- we aren't actually reusing code, since
AddressBookTest#isTagObjectInAddressBookList() isn't an equivalent
replacement for AddressBook#addPerson().

AddressBook#containsTag() should be removed as unused code contributes
to maintenance and comprehension overheads.

Let's remove AddressBook#containsTag().

AddressBook#addTag() adds a Tag to the master list of Tags in
AddressBook.

This method is not used anywhere, and can be classified as unused code.
There are no commands that support the addition of Tags only, and it is
also not part of any learning objectives. Furthermore,
AddressBook#syncTagsWithMasterList() already handles the addition of
Tags from a Person gracefully without using exceptions. It should be
removed as unused code contributes to maintenance and comprehension
overheads.

Let's remove AddressBook#addTag().
UniqueTagList#add() adds a Tag to the list of unique Tags, and throws an
exception if it is a duplicate of an existing Tag in the list.

With the removal of AddressBook#addTag(), this method is not used
anywhere, and can be classified as unused code. It should be removed as
unused code contributes to maintenance and comprehension overheads.

Let's remove UniqueTagList#add().
AddressBook#removeTag() removes a Tag from the master list of Tags and
from any Person in AddressBook.

This method is not used anywhere, and can be classified as unused code.
There are no commands that support the removal of Tags only, and it is
also not part of any learning objectives. It should be removed as unused
code contributes to maintenance and comprehension overheads.

Let's remove AddressBook#removeTag().
UniqueTagList#remove() removes a Tag from the list of unique Tags, and
throws an exception if it is not found in the list.

With the removal of AddressBook#removeTag(), this method is not used
anywhere, and can be classified as unused code. It should be removed as
unused code contributes to maintenance and comprehension overheads.

Let's remove UniqueTagList#remove().
@PierceAndy PierceAndy force-pushed the 169-unused-tag-methods branch 2 times, most recently from 022c23d to 4cfe9a5 Compare February 15, 2017 14:18
@CanIHasReview-bot
Copy link

v4

@PierceAndy submitted v4 for review.

(📚 Archive) (📈 Interdiff between v3 and v4)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level2.git refs/pr/179/4/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@PierceAndy
Copy link
Contributor Author

v4

AddressBook: remove unused containsTag()

AddressBook#containsTag() checks if the master list of Tags contains a
Tag with the same value as the given Tag.

This method is not used anywhere, and can be classified as unused code.
There are no commands that support it, and it is also not part of any
learning objectives. While it is used in tests, its functionality is
superseded by AddressBookTest#isTagObjectInAddressBookList(), and can be
replaced by the latter in these tests. AddressBook#containsTag() should
be removed as unused code contributes to maintenance and comprehension
overheads.

Let's remove AddressBook#containsTag().

ddressBookTest#isTagObjectInAddressBookList() is chosen over
AddressBook#containsTag() because the former supersedes the latter in
functionalities, and the former has to exist with or without the latter
as the former contains test-specific checks.
AddressBookTest#isTagObjectInAddressBookList() checks if the master list
of Tags from a given AddressBook contains the given Tag object by
reference, thus not only checking if a Tag value is in the master list
like AddressBook#containsTag() does, but also checks that Person objects
points to Tag objects in the master Tag list instead of keeping its own
copies of Tags. The alternative of updating AddressBook#containsTag() to
compare by reference to take over the responsibilities of
AddressBookTest#isTagObjectInAddressBookList() is inconsistent with our
API design, as it would mean adding a method used only in tests to
production code.

@damithc
Copy link
Contributor

damithc commented Feb 15, 2017

Tried to shorten the commit message. Does it cover all the points?

AddressBook#containsTag() is not used in the production code.
While it is used in test code, its use can be replaced by 
AddressBookTest#isTagObjectInAddressBookList().

Let's remove AddressBook#containsTag().

Notes: 
* Why not keep AddressBook#containsTag() and remove 
AddressBookTest#isTagObjectInAddressBookList() instead?
The former does a value equality test while the latter goes further
and does a reference equality test. The test code requires a 
reference equality test to verify Person objects refer to Tag
objects in the common tag list instead of keeping its own copies
of Tag objects. 
* Why not change AddressBook#containsTag() to use reference
equality and use that in tests?
Doing so will make AddressBook#containsTag()'s semantics 
inconsistent with the rest of our API.

AddressBook#containsTag() checks if the master list of Tags contains a
Tag with the same value as the given Tag.

AddressBook#containsTag() is not used in the production code. While it
is used in test code, its use can be replaced by
AddressBookTest#isTagObjectInAddressBookList().

Let's remove AddressBook#containsTag().

Notes:
* Why not keep AddressBook#containsTag() and remove
AddressBookTest#isTagObjectInAddressBookList() instead? The former does
a value equality test while the latter goes further and does a reference
equality test. The test code requires a reference equality test to
verify Person objects refer to Tag objects in the common tag list
instead of keeping its own copies of Tag objects.
* Why not change AddressBook#containsTag() to use reference equality and
use that in tests? Doing so will make AddressBook#containsTag()'s
semantics inconsistent with the rest of our API.
@CanIHasReview-bot
Copy link

v5

@PierceAndy submitted v5 for review.

(📚 Archive) (📈 Interdiff between v4 and v5)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level2.git refs/pr/179/5/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@PierceAndy
Copy link
Contributor Author

PierceAndy commented Feb 16, 2017

v5

  • Shortened [v4 5/5] commit message

@damithc damithc merged commit 4f5b987 into se-edu:master Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants