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

Sharing iP code quality feedback [for @amosting] - Round 2 #2

Open
soc-se-script opened this issue Oct 16, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @amosting] - Round 2 #2

soc-se-script opened this issue Oct 16, 2023 · 0 comments

Comments

@soc-se-script
Copy link

@amosting We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.

Aspect: Tab Usage

No easy-to-detect issues 👍

Aspect: Naming boolean variables/methods

No easy-to-detect issues 👍

Aspect: Brace Style

No easy-to-detect issues 👍

Aspect: Package Name Style

Example from src/main/java/Jarvis/Deadline.java lines 1-1:

package Jarvis;

Example from src/main/java/Jarvis/Event.java lines 1-1:

package Jarvis;

Example from src/main/java/Jarvis/IncorrectJarvisCommandException.java lines 1-1:

package Jarvis;

Suggestion: Follow the package naming convention specified by the coding standard.

Aspect: Class Name Style

No easy-to-detect issues 👍

Aspect: Dead Code

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/Jarvis/Parser.java lines 99-147:

    public String isWrongFormat(String inputCommand, String validInputCommand) {

        assert !inputCommand.isEmpty() : "inputCommand parameter in isWrongFormat() is an empty string";
        assert !validInputCommand.isEmpty() : "validInputCommand parameter in isWrongFormat() is an empty string";

        // since command is valid, check if formatting of the command is correct
        boolean markMatch = inputCommand.matches("mark \\d+");
        boolean uncheckMatch = inputCommand.matches("unmark \\d+");
        boolean todoMatch = inputCommand.matches("todo .+ (low|medium|high)");
        boolean deadlineMatch = inputCommand.matches("deadline .+ /.+ (low|medium|high)");
        boolean eventMatch = inputCommand.matches("event .+ /.+ /.+ (low|medium|high)");

        if (validInputCommand.equals("mark") && !markMatch) { // if mark command but wrong format
            try {
                throw new WrongJarvisCommandFormatException(
                        "Apologies Sir, the format of the mark command you provided is incorrect.");
            } catch (WrongJarvisCommandFormatException e) {
                return Ui.getWrongFormatMessage("mark", e);
            }
        } else if (validInputCommand.equals("uncheck") && !uncheckMatch) { // if uncheck command but wrong format
            try {
                throw new WrongJarvisCommandFormatException(
                        "Apologies Sir, the format of the uncheck command you provided is incorrect.");
            } catch (WrongJarvisCommandFormatException e) {
                return Ui.getWrongFormatMessage("uncheck", e);
            }
        } else if (validInputCommand.equals("todo") && !todoMatch) { // if todo command but wrong format
            try {
                throw new WrongJarvisCommandFormatException(
                        "Apologies Sir, the format of the todo command you provided is incorrect.");
            } catch (WrongJarvisCommandFormatException e) {
                return Ui.getWrongFormatMessage("todo", e);
            }
        } else if (validInputCommand.equals("deadline") && !deadlineMatch) { // if deadline command but wrong format
            try {
                throw new WrongJarvisCommandFormatException(
                        "Apologies Sir, the format of the deadline command you provided is incorrect.");
            } catch (WrongJarvisCommandFormatException e) {
                return Ui.getWrongFormatMessage("deadline", e);
            }
        } else { // if event command but wrong format
            try {
                throw new WrongJarvisCommandFormatException(
                        "Apologies Sir, the format of the event command you provided is incorrect.");
            } catch (WrongJarvisCommandFormatException e) {
                return Ui.getWrongFormatMessage("event", e);
            }
        }
    }

Example from src/main/java/Jarvis/Parser.java lines 159-244:

    public String parseCommand(Storage storage, TaskList tasks, String userInput) throws
            IncorrectJarvisCommandException, InvalidTaskNumberException, WrongJarvisCommandFormatException {

        Pattern todoPattern = Pattern.compile("(todo) (.+) (low|medium|high)");
        Pattern deadlinePattern = Pattern.compile("(deadline) (.+) /by (.+) (low|medium|high)");
        Pattern eventPattern = Pattern.compile("(event) (.+) /from (.+) /to (.+) (low|medium|high)");
        Pattern deletePattern = Pattern.compile("(delete) (\\d+)");
        Pattern findPattern = Pattern.compile("(find) (.+)");

        Matcher todoMatcher = todoPattern.matcher(userInput);
        Matcher deadlineMatcher = deadlinePattern.matcher(userInput);
        Matcher eventMatcher = eventPattern.matcher(userInput);
        Matcher deleteMatcher = deletePattern.matcher(userInput);
        Matcher findMatcher = findPattern.matcher(userInput);

        String nameOfValidCommand = isValidCommand(userInput);

        if (userInput.matches("list")) { // if "list" is entered
            return Ui.getTaskList(tasks);

        } else if (userInput.matches("bye")) { // if "bye" is entered
            storage.deleteContents();
            storage.save(tasks); // save task list to data file after bye is entered
            return Ui.getByeMessage();

        } else if (userInput.matches("mark \\d+")
                || userInput.matches("uncheck \\d+")) { // if "mark" or "uncheck" is entered

            int taskNum = Integer.parseInt(userInput.substring(userInput.length() - 1));
            if (!tasks.isValidTaskNumber(taskNum)) {
                return null;
            }

            Task currentTask = tasks.getTask(taskNum - 1);
            if (userInput.matches("uncheck \\d+")) { // if "uncheck" is entered
                currentTask.setDone(false);
                return Ui.getUncheckMessage(currentTask);

            } else { // if "mark" is entered
                currentTask.setDone(true);
                return Ui.getMarkMessage(currentTask);
            }

        } else if (todoMatcher.matches()
                || deadlineMatcher.matches()
                || eventMatcher.matches()) { // if task command is entered
            Task newTask;
            if (todoMatcher.matches()) { // if "todo" is entered
                String taskDescription = todoMatcher.group(2);
                String priority = todoMatcher.group(3);
                newTask = new ToDo(taskDescription, parsePriority(priority));

            } else if (deadlineMatcher.matches()) { // if "deadline" is entered
                String taskDescription = deadlineMatcher.group(2);
                String by = deadlineMatcher.group(3);
                String priority = deadlineMatcher.group(4);
                newTask = new Deadline(taskDescription, by, parsePriority(priority));

            } else { // if "event" is entered
                String taskDescription = eventMatcher.group(2);
                String from = eventMatcher.group(3);
                String to = eventMatcher.group(4);
                String priority = eventMatcher.group(5);
                newTask = new Event(taskDescription, from, to, parsePriority(priority));

            }
            tasks.appendTask(newTask);
            return Ui.getTaskMessage(newTask, tasks);

        } else if (deleteMatcher.matches()) { // if delete is entered
            int taskNum = Integer.parseInt(deleteMatcher.group(2));
            if (tasks.isValidTaskNumber(taskNum)) {
                tasks.deleteTask(taskNum - 1);
                Task deletedTask = tasks.getTask(taskNum);
                return Ui.getDeleteMessage(deletedTask ,tasks);
            }

        } else if (findMatcher.matches()) { // if find is entered
            String keyword = findMatcher.group(2);
            return Ui.getFoundTaskMessage(tasks.findTask(keyword));

        } else { // if none of the above commands go through
            return isWrongFormat(userInput, nameOfValidCommand);
        }
        return null;
    }

Example from src/main/java/Jarvis/TaskList.java lines 21-72:

    public TaskList(String tasks) { // tasks is a string

        if (tasks.isEmpty()) {
            taskList = new ArrayList<>();
        } else {
            String[] stringTasks = tasks.split("\n");
            Pattern todoPattern = Pattern.compile(
                    "\\[T\\]\\[(X|\\s)\\]\\[(L|M|H)\\] (.+)"); // [T][-][L/M/H] xxxx
            Pattern deadlinePattern = Pattern.compile(
                    "\\[D\\]\\[(X|\\s)\\]\\[(L|M|H)\\] (.+) \\(by: (.+)\\)"); // [D][-][L/M/H] xxxx (by: xxxxxx)
            Pattern eventPattern = Pattern.compile(
                    "\\[E\\]\\[(X|\\s)\\]\\[(L|M|H)\\] (.+) \\(from: (.+) to: (.+)\\)"); // [E][-][L/M/H] xxxx (from: xxxxxx to: xxxxxx)
            // [E][ ][H] project meeting (from: Monday 2pm to: 4pm)

            taskList = new ArrayList<>();
            for (int i = 0; i < stringTasks.length; i++) {
                Matcher todoMatcher = todoPattern.matcher(stringTasks[i]);
                Matcher deadlineMatcher = deadlinePattern.matcher(stringTasks[i]);
                Matcher eventMatcher = eventPattern.matcher(stringTasks[i]);

                Task newTask;
                if (todoMatcher.matches()) {
                    String description = todoMatcher.group(3);
                    String priority = todoMatcher.group(2);
                    newTask = new ToDo(description, priority);
                    if (todoMatcher.group(1).equals("X")) {
                        newTask.setDone(true);
                    }
                } else if (deadlineMatcher.matches()) {
                    String description = deadlineMatcher.group(3);
                    String by = deadlineMatcher.group(4);
                    String priority = deadlineMatcher.group(2);
                    newTask = new Deadline(description, by, priority);
                    if (deadlineMatcher.group(1).equals("X")) {
                        newTask.setDone(true);
                    }
                } else  {
                    eventMatcher.matches();
                    String description = eventMatcher.group(3);
                    String from = eventMatcher.group(4);
                    String to = eventMatcher.group(5);
                    String priority = eventMatcher.group(2);
                    newTask = new Event(description, from, to, priority);
                    if (eventMatcher.group(1).equals("X")) {
                        newTask.setDone(true);
                    }
                }

                taskList.add(newTask); // add the task to the task list
            }
        }
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Class size

No easy-to-detect issues 👍

Aspect: Header Comments

Example from src/main/java/Jarvis/Task.java lines 59-61:

    /**
     * Abstract method for string to date conversion
     */

Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.

Aspect: Recent Git Commit Message

possible problems in commit 4b00c23:


Renamed to Ui.png


  • Not in imperative mood (?)

possible problems in commit 6f2d229:


Add User Guide.
Edited README.md to have a proper user guide for Jarvis chatbot.
Edited some small Ui class return strings to ensure proper and consistent formatting.


  • Subject line should not end with a period
  • No blank line between subject and body
  • body not wrapped at 72 characters: e.g., Edited some small Ui class return strings to ensure proper and consistent formatting.

possible problems in commit 6ecc802:


Add logic to handle new priority feature, for checking of correct user input.
Edited regex expression in TaskList to handle priority field.
Edited return statements in Ui.java to return correct task format for new priority feature.


  • Longer than 72 characters
  • Subject line should not end with a period
  • No blank line between subject and body
  • body not wrapped at 72 characters: e.g., Edited return statements in Ui.java to return correct task format for new priority feature.

Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).

Aspect: Binary files in repo

No easy-to-detect issues 👍


❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality issues.

ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected] if you want to follow up on this post.

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

No branches or pull requests

1 participant