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 @KJunWei] - Round 2 #5

Open
soc-se-bot-red opened this issue Oct 11, 2022 · 0 comments
Open

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

soc-se-bot-red opened this issue Oct 11, 2022 · 0 comments

Comments

@soc-se-bot-red
Copy link

@KJunWei 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

No easy-to-detect issues 👍

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/duke/command/Command.java lines 97-152:

    public static Command handleMultiWordCommand(String keyword, String s) throws DukeException {
        switch (keyword) {
        case "todo":
            return new AddCommand(Task.TaskType.TODO, s.substring(5), null);
        case "deadline": {
            try {
                String[] tempSplit = s.substring(9).split(" /by ");
                if (tempSplit.length == 1) {
                    throw new DukeException("deadline format");
                } else {
                    return new AddCommand(Task.TaskType.DEADLINE, tempSplit[0], LocalDate.parse(tempSplit[1]));
                }
            } catch (DateTimeParseException e) {
                throw new DukeException("deadline format");
            }
        }
        case "event": {
            try {
                String[] tempSplit = s.substring(6).split(" /at ");
                if (tempSplit.length == 1) {
                    throw new DukeException("event format");
                } else {
                    return new AddCommand(Task.TaskType.EVENT, tempSplit[0], LocalDate.parse(tempSplit[1]));
                }
            } catch (DateTimeParseException e) {
                throw new DukeException("event format");
            }
        }
        case "delete":
            try {
                int location = Integer.parseInt(s.substring(7)) - 1;
                return new DeleteCommand(location);
            } catch (NumberFormatException e) {
                throw new DukeException("non integer input when deleting");
            }
        case "mark":
            try {
                int location = Integer.parseInt(s.substring(5)) - 1;
                return new MarkCommand(true, location);
            } catch (NumberFormatException e) {
                throw new DukeException("non integer input when marking");
            }
        case "unmark":
            try {
                int location = Integer.parseInt(s.substring(7)) - 1;
                return new MarkCommand(false, location);
            } catch (NumberFormatException e) {
                throw new DukeException("non integer input when marking");
            }
        case "find":
            String substring = s.substring(5);
            return new FindCommand(substring);
        default:
            throw new DukeException("unknown");
        }
    }

Example from src/main/java/duke/ui/Ui.java lines 90-155:

    public String sendAndReturnMessage(Command.ActionKeywords keyword, Task task, String... values) {
        int numOfTasks = 0;
        String message = "";
        if (values.length >= 1) {
            numOfTasks = Integer.parseInt(values[0]);
        }
        if (values.length >= 2) {
            message = values[1];
        }
        switch (keyword) {
        case DEADLINE:
        case TODO:
        case EVENT: {
            return formatMessage("Got it. I've added this task:\n"
                    + INDENTATION + EXTRA_INDENTATION + task + "\n"
                    + INDENTATION + "Now you have " + numOfTasks
                    + (numOfTasks < 2 ? " task" : " tasks") + " in the list.");
        }
        case DELETE: {
            return formatMessage("Noted. I've removed the task:\n"
                    + INDENTATION + EXTRA_INDENTATION + task + "\n"
                    + INDENTATION + "Now you have " + numOfTasks
                    + (numOfTasks < 2 ? " task" : " tasks") + " in the list.");
        }
        case LIST: {
            String msg;
            if (message.equals("")) {
                msg = formatMessage("There are currently no tasks in your list");
            } else {
                msg = formatMessage("Here are the task(s) in your list:\n"
                        + INDENTATION + message);
            }
            return msg;
        }
        case MARK: {
            return formatMessage("Nice! I've marked this task as done:\n"
                    + INDENTATION + EXTRA_INDENTATION + task);
        }
        case UNMARK: {
            return formatMessage("OK, I've marked this task as not done yet:\n"
                    + INDENTATION + EXTRA_INDENTATION + task);
        }
        case FIND: {
            String msg;
            if (message.equals("")) {
                msg = formatMessage("Sorry, there are no matching tasks in your list");
            } else {
                msg = formatMessage("Here are the matching tasks in your list:\n"
                        + INDENTATION + message);
            }
            return msg;
        }
        case REMIND: {
            String msg;
            if (message.equals("")) {
                msg = formatMessage("You have no uncompleted deadline tasks!");
            } else {
                msg = formatMessage("Here are the uncompleted tasks in your list:\n"
                        + INDENTATION + message);
            }
            return msg;
        }
        default:
            return null;
        }
    }

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/duke/Duke.java lines 88-92:

    /**
     * Main method.
     *
     * @param args Given arguments.
     */

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 (Subject Only)

No easy-to-detect issues 👍

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