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

Removal of repeatable parameters #190

Merged

Conversation

Eclipse-Dominator
Copy link
Contributor

@Eclipse-Dominator Eclipse-Dominator commented Jun 6, 2023

This PR an alternative that Fixes #162 (other alternatives: #176, #181)

In this PR, we treat repeated parameters as an error.

If a single-valued parameter is repeated multiple times in a 
command, only the last occurrence is taken.  This allows the user
to correct a mistake in a parameter value by simply typing it again,
which may be faster than moving the cursor back to the original
parameter values and editing it. This feature serves as a good
example of 'going the extra mile to optimize the application for
target users' (i.e., users who can type fast).
However, this feature can cause certain user errors to go unnoticed
e.g., unintended repetition caused by a typo in parameter name

Alternatives considered:
(a) Retain current behavior but give a friendly warning to the user
    that a parameter was 'overridden'. 
(b) Remove this feature i.e., treat repeated single-valued
    parameters    as an error, and reject the command with an
    error message.

Alternative (a) requires significantly more complicated code
(see #181), steepening the learning curve for for new programmers.
Given that this application is primarily meant for training
novice programmers, the impact on the learning curve is not worth
the benefit of retaining this feature.

Therefore, let's do option (b).

@canihasreview
Copy link

canihasreview bot commented Jun 6, 2023

Click here to submit a new iteration when this PR is ready for review.

See this repository's contribution guide for more information.

@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #190 (4a4144d) into master (bd48d59) will increase coverage by 0.16%.
The diff coverage is 91.66%.

@@             Coverage Diff              @@
##             master     #190      +/-   ##
============================================
+ Coverage     74.00%   74.16%   +0.16%     
- Complexity      420      428       +8     
============================================
  Files            71       71              
  Lines          1281     1293      +12     
  Branches        126      127       +1     
============================================
+ Hits            948      959      +11     
+ Misses          301      300       -1     
- Partials         32       34       +2     
Impacted Files Coverage Δ
src/main/java/seedu/address/logic/Messages.java 87.50% <75.00%> (-4.17%) ⬇️
...a/seedu/address/logic/parser/AddCommandParser.java 100.00% <100.00%> (ø)
...a/seedu/address/logic/parser/ArgumentMultimap.java 100.00% <100.00%> (ø)
.../seedu/address/logic/parser/EditCommandParser.java 92.59% <100.00%> (+0.28%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@canihasreview
Copy link

canihasreview bot commented Jun 7, 2023

v1

@Eclipse-Dominator submitted v1 for review.

(📚 Archive)

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

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

1 similar comment
@canihasreview
Copy link

canihasreview bot commented Jun 7, 2023

v1

@Eclipse-Dominator submitted v1 for review.

(📚 Archive)

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

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

@damithc
Copy link
Contributor

damithc commented Jun 7, 2023

@Eclipse-Dominator Now that we have three alternatives, what your thoughts about selecting one?
Also, in each of the three PR descriptions, you can mention the other two so that anyone visiting the PR can see how they fit into the big picture.

@damithc
Copy link
Contributor

damithc commented Jun 8, 2023

Repeated Parameters show warning: #176
Repeated Parameters show warning of repeated prefixes: #181
Repeated Parametes treated as errors: #190

Updated the PR description instead.

@se-edu se-edu deleted a comment from Eclipse-Dominator Jun 8, 2023
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.

Some initial comments ...

@damithc
Copy link
Contributor

damithc commented Jun 12, 2023

@Eclipse-Dominator As discussed, let's proceed with this approach.

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.

Added a few more comments.

@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from ba48384 to 7d3bb2b Compare June 12, 2023 22:08
@canihasreview
Copy link

canihasreview bot commented Jun 12, 2023

v2

@Eclipse-Dominator submitted v2 for review.

(📚 Archive) (📈 Interdiff between v1 and v2) (📈 Range-Diff between v1 and v2)

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

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

@canihasreview canihasreview bot requested a review from damithc June 12, 2023 22:09
Copy link

@jundatan jundatan left a comment

Choose a reason for hiding this comment

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

Suggestion to change the message for duplicate person.

@@ -9,5 +14,21 @@ public class Messages {
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS = "Detected multiple values for the following field%s: "
+ "%s.\nPlease only a single value for those fields\n";

Choose a reason for hiding this comment

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

I feel that this Message should be worded properly. Perhaps it will be better to have a message like "Multiple values detected for the following field%s: " + "%s.\nOnly one value is allowed for these fields\n".

@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from 7d3bb2b to 6210dce Compare June 13, 2023 09:31
@canihasreview
Copy link

canihasreview bot commented Jun 13, 2023

v3

@Eclipse-Dominator submitted v3 for review.

(📚 Archive) (📈 Interdiff between v2 and v3) (📈 Range-Diff between v2 and v3)

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

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

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.

Some suggestions added


return String.format(MESSAGE_DUPLICATE_FIELDS, duplicateFields.size() > 1 ? "s" : "",
String.join(" ", duplicateFields), duplicateFields.size() > 1 ? "these" : "this");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are complicating this code too much for too little payback. No need to bother with singular/plural differences. Something like the following?

Multiple values specified for the following single-valued filed(s): ...

Copy link
Contributor Author

@Eclipse-Dominator Eclipse-Dominator Jun 14, 2023

Choose a reason for hiding this comment

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

Personally, I think over complicating this code is okay here since everything related to the messages have been abstracted to within Messages. So, there won't be any additional code duplication and its self-contained to within Messages.

That being said, I think changing it the message to

Multiple values specified for the following single-valued field(s): ...
Please only supply a single value for the field(s) mentioned above.

can make it appear more user-friendly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I think over complicating this code is okay here since everything related to the messages have been abstracted to within Messages. So, there won't be any additional code duplication and its self-contained to within Messages.

Always be as economical as possible with code. Every line of code is an additional burden every project member has to carry for the rest of the lifetime of the project.

That being said, I think changing it the message to

Multiple values specified for the following single-valued field(s): ...
Please only supply a single value for the field(s) mentioned above.
can make it appear more user-friendly?

Not totally opposed, but I have some concerns:

  1. Feels a bit redundant. Check how the UI present this error to the user. Perhaps the first sentence is enough for the user to understand the problem.
  2. Check other error messages. If they don't have Please do such and such ... part, we don't want to make this specific error message different from others.

/**
* Formats the duplicate prefixes into an error message.
*/
public static String getDuplicatePrefixesToMessage(Set<Prefix> duplicatePrefixes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

alternative to consider:

Suggested change
public static String getDuplicatePrefixesToMessage(Set<Prefix> duplicatePrefixes) {
public static String getDuplicatePrefixesToMessage(Prefix... duplicatePrefixes) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept it intentionally this to avoid ordering of the fields in the message to avoid complications when doing unit test etc.
It is possible to sort the field within this method but I feel that supplying it with a Set will make it cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of creating Set objects everywhere this method is called, you can create the Set inside the method at the start?

Copy link
Contributor Author

@Eclipse-Dominator Eclipse-Dominator Jun 14, 2023

Choose a reason for hiding this comment

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

Yes, but the code technically is really only called once in production code and the rest of it is called in unit test.

Which is called below.

    /**
     * Throws a {@code ParseException} if any of the prefixes given in {@code prefixes} appeared more than
     * once among the arguments.
     */
    public void verifyNoDuplicatePrefixesFor(Prefix... prefixes) throws ParseException {
        Set<Prefix> duplicatedPrefixes = new HashSet<>();
        Set<Prefix> prefixSet = Set.of(prefixes);
        argMultimap.forEach((key, list) -> {
            if (list.size() > 1 && prefixSet.contains(key)) {
                duplicatedPrefixes.add(key);
            }
        });

        if (!duplicatedPrefixes.isEmpty()) {
            throw new ParseException(Messages.getDuplicatePrefixesToMessage(duplicatedPrefixes));
        }
    }

Converting getDuplicatePrefixesToMessage() to take in Prefix... or Prefix[] will involve calling duplicatedPrefixes.toArray(Prefix[]::new)) which will cause it to be converted once again into a Set object when inside the method.

This is true unless we are using a fixed-size array for duplicatedPrefixes or alternative we can convert the whole process as a java stream and convert it to an array.

I will experiment processing the above with java stream and see its readability in the next version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the code is cleaner with java stream, I will update the relevant code.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, you are doing something very similar in here:

 public void verifyNoDuplicatePrefixesFor(Prefix... prefixes) throws ParseException {
        Set<Prefix> duplicatedPrefixes = new HashSet<>();
        Set<Prefix> prefixSet = Set.of(prefixes);

@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from 6210dce to a4b0fa9 Compare June 14, 2023 03:15
@canihasreview
Copy link

canihasreview bot commented Jun 14, 2023

v4

@Eclipse-Dominator submitted v4 for review.

(📚 Archive) (📈 Interdiff between v3 and v4) (📈 Range-Diff between v3 and v4)

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

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

@canihasreview canihasreview bot requested a review from damithc June 14, 2023 03:15
@canihasreview
Copy link

canihasreview bot commented Jun 14, 2023

v5

@Eclipse-Dominator submitted v5 for review.

(📚 Archive) (📈 Interdiff between v4 and v5) (📈 Range-Diff between v4 and v5)

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

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

@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from dd943c5 to 9d63a65 Compare June 14, 2023 03:26
@canihasreview
Copy link

canihasreview bot commented Jun 14, 2023

v6

@Eclipse-Dominator submitted v6 for review.

(📚 Archive) (📈 Interdiff between v5 and v6) (📈 Range-Diff between v5 and v6)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/6/head:BRANCHNAME

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

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.

Some further suggestions

docs/UserGuide.md Outdated Show resolved Hide resolved
src/main/java/seedu/address/commons/core/Messages.java Outdated Show resolved Hide resolved
@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch 2 times, most recently from 84bc1cd to 1e74f73 Compare June 14, 2023 05:57
@canihasreview
Copy link

canihasreview bot commented Jul 3, 2023

v10

@Eclipse-Dominator submitted v10 for review.

(📚 Archive) (📈 Interdiff between v9 and v10) (📈 Range-Diff between v9 and v10)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/10/head:BRANCHNAME

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

@Eclipse-Dominator
Copy link
Contributor Author

Eclipse-Dominator commented Jul 3, 2023

Resolve rebase conflicts.

@damithc
Copy link
Contributor

damithc commented Jul 3, 2023

@Eclipse-Dominator Looks like the rebase wasn't entirely correct. There are some unrelated code in this PR.

@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from d7b3553 to 7841d23 Compare July 10, 2023 13:09
@canihasreview
Copy link

canihasreview bot commented Jul 10, 2023

v11

@Eclipse-Dominator submitted v11 for review.

(📚 Archive) (📈 Interdiff between v10 and v11) (📈 Range-Diff between v10 and v11)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/11/head:BRANCHNAME

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

@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from 7841d23 to e407b81 Compare July 13, 2023 00:11
@canihasreview
Copy link

canihasreview bot commented Jul 13, 2023

v12

@Eclipse-Dominator submitted v12 for review.

(📚 Archive) (📈 Interdiff between v11 and v12) (📈 Range-Diff between v11 and v12)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/12/head:BRANCHNAME

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

@canihasreview canihasreview bot requested a review from damithc July 13, 2023 00:37
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.

Some comments added (did not review the test code though).

docs/UserGuide.md Show resolved Hide resolved
src/main/java/seedu/address/commons/core/Messages.java Outdated Show resolved Hide resolved
src/main/java/seedu/address/commons/core/Messages.java Outdated Show resolved Hide resolved
@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch 3 times, most recently from 938be75 to ce1f59b Compare July 13, 2023 13:37
@canihasreview
Copy link

canihasreview bot commented Jul 13, 2023

v13

@Eclipse-Dominator submitted v13 for review.

(📚 Archive) (📈 Interdiff between v12 and v13) (📈 Range-Diff between v12 and v13)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/13/head:BRANCHNAME

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

@canihasreview canihasreview bot requested a review from damithc July 13, 2023 13:42
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.

Just a minor question. I think we are close to home on this one. Let me ask others to have a look as well.

@damithc
Copy link
Contributor

damithc commented Jul 13, 2023

@se-edu/tech-team-level1 for your review ...

Copy link

@dlimyy dlimyy left a comment

Choose a reason for hiding this comment

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

Overall, LGTM! Just some minor suggestions below

* Throws a {@code ParseException} if any of the prefixes given in {@code prefixes} appeared more than
* once among the arguments.
*/
public void verifyNoDuplicatePrefixesFor(Prefix... prefixes) throws ParseException {
Copy link

Choose a reason for hiding this comment

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

Could consider shortening the name of the method to verifyNoDuplicatePrefixes as the 'For' does not seem to be very necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

It reads as a natural statement e.g., verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_ADDRESS) i.e., verify no duplicate prefixes for A, B, ..
But OK to remove.
Can also consider verifyNoDuplicatesFor as Prefix is implied by the parameter type.

docs/UserGuide.md Show resolved Hide resolved
src/main/java/seedu/address/logic/Messages.java Outdated Show resolved Hide resolved
@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from ce1f59b to 3d2c2df Compare July 14, 2023 12:09
@canihasreview
Copy link

canihasreview bot commented Jul 14, 2023

v14

@Eclipse-Dominator submitted v14 for review.

(📚 Archive) (📈 Interdiff between v13 and v14) (📈 Range-Diff between v13 and v14)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/14/head:BRANCHNAME

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

@canihasreview canihasreview bot requested a review from damithc July 14, 2023 12:16
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.

Two commented you missed.

src/main/java/seedu/address/logic/Messages.java Outdated Show resolved Hide resolved
If a single-valued parameter is repeated multiple times in a command,
only the last occurrence is taken. This allows the user to correct a
mistake in a parameter value by simply typing it again, which may be
faster than moving the cursor back to the original parameter values and
editing it. This feature serves as a good example of 'going the extra
mile to optimize the application for target users' (i.e., users who can
type fast).
However, this feature can cause certain user errors to go unnoticed
e.g., unintended repetition caused by a typo in parameter name

Alternatives considered:
(a) Retain current behavior but give a friendly warning to the user
    that a parameter was 'overridden'.
(b) Remove this feature i.e., treat repeated single-valued parameters
    as an error, and reject the command with an error message.

Alternative (a) requires significantly more complicated code (see se-edu#181),
steepening the learning curve for for new programmers. Given that this
application is primarily meant for training novice programmers, the
impact on the learning curve is not worth the benefit of retaining this
feature.

Therefore, let's do option (b).
@Eclipse-Dominator Eclipse-Dominator force-pushed the change-repeated-parameter-to-error branch from 3d2c2df to 4a4144d Compare July 14, 2023 14:22
@canihasreview
Copy link

canihasreview bot commented Jul 14, 2023

v15

@Eclipse-Dominator submitted v15 for review.

(📚 Archive) (📈 Interdiff between v14 and v15) (📈 Range-Diff between v14 and v15)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/15/head:BRANCHNAME

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

@canihasreview canihasreview bot requested a review from damithc July 14, 2023 14:23
Copy link

@SPWwj SPWwj left a comment

Choose a reason for hiding this comment

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

Code works as expected. LGTM.

@damithc damithc merged commit a976ec9 into se-edu:master Jul 19, 2023
15 checks passed
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.

Give a warning when a parameter is repeated in a user command
5 participants