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 @narwhalsilent] #3

Open
nus-se-script opened this issue Feb 17, 2024 · 0 comments
Open

Sharing iP code quality feedback [for @narwhalsilent] #3

nus-se-script opened this issue Feb 17, 2024 · 0 comments

Comments

@nus-se-script
Copy link

@narwhalsilent We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.

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/knight/CommandParser.java lines 47-84:

    private static void handleNonstandardCommand(String s) throws NonstandardCommandException {
        if (s.startsWith("bye")) { // nonstandard command
            throw new NonstandardCommandException("Thou canst bid me farewell simply with:\nbye");
        } else if (s.startsWith("list")) {
            throw new NonstandardCommandException("Though canst view thy list simply with:\nlist");
        } else if (s.matches("find")) {
            throw new NonstandardCommandException(
                    "Thou shouldst specify a keyword to search for in thy list of tasks:\n"
                            + "find [keyword]");
        } else if (s.startsWith("mark")) {
            throw new NonstandardCommandException(
                    "Take heed, for thou shouldst reference the task thou wishest to alter by its index:\n"
                            + "mark [index]");
        } else if (s.startsWith("unmark")) {
            throw new NonstandardCommandException(
                    "Take heed, for thou shouldst reference the task thou wishest to alter by its index:\n"
                            + "unmark [index]");
        } else if (s.startsWith("delete")) {
            throw new NonstandardCommandException(
                    "Take heed, for thou shouldst reference the task thou wishest to alter by its index:\n"
                            + "delete [index]");
        } else if (s.startsWith("todo")) {
            throw new NonstandardCommandException(
                    "Thou shouldst forge a todo task such as so:\n"
                            + "todo [description]");
        } else if (s.startsWith("deadline")) {
            throw new NonstandardCommandException(
                    "Thou shouldst forge a deadline task such as so:\n"
                            + "deadline [description] /by [time]");
        } else if (s.startsWith("event")) {
            throw new NonstandardCommandException(
                    "Thou shouldst forge an event task such as so:\n"
                            + "event [description] /from [start time] /to [end time]");
        } else {
            throw new NonstandardCommandException(
                    "I beg thine pardon, but I am clueless of the meaning of your utterance.");
        }
    }

Example from src/main/java/knight/TaskList.java lines 26-123:

    void executeCommand(Command commandType, String message) {
        if (commandType == Command.LIST) {
            if (tasks.isEmpty()) {
                Ui.speak("Your Excellency, thy list remaineth free of tasks at this present moment.");
            } else {
                Ui.speak("Behold, the duties thou hast assigned:\n" + this.toString());
            }
        } else if (commandType == Command.SAVE) {
            Storage.writeToFile(this);
            Ui.speak("Thy list hath been saved to thy scrolls of history.");
        } else if (commandType == Command.MARK) {
            int index = Integer.parseInt(message.substring(5));
            Task task;

            try {
                task = tasks.get(index - 1);
            } catch (IndexOutOfBoundsException e) {
                Ui.speak("I regret to inform thee, Your Excellency, "
                        + "that thou lackest a task bearing this index in thy list.");
                return;
            }

            task.mark();
            Ui.speak("Thy task hath been marked as done.\n" + task);
        } else if (commandType == Command.UNMARK) {
            int index = Integer.parseInt(message.substring(7));
            Task task;

            try {
                task = tasks.get(index - 1);
            } catch (IndexOutOfBoundsException e) {
                Ui.speak("I regret to inform thee, Your Excellency, "
                        + "that thou lackest a task bearing this index in thy list.");
                return;
            }

            task.unmark();
            Ui.speak("Thy task hath been unmarked.\n" + task);
        } else if (commandType == Command.DELETE) {
            int index = Integer.parseInt(message.substring(7));
            Task task;

            try {
                task = tasks.get(index - 1);
            } catch (IndexOutOfBoundsException e) {
                Ui.speak("I regret to inform thee, Your Excellency,"
                        + "that thou lackest a task bearing this index in thy list.");
                return;
            }

            tasks.remove(index - 1);
            Ui.speak("Thy task hath been removed from thy list.\n" + task);
        } else if (commandType == Command.TODO) {
            Task task = new ToDo(message.substring(5));
            tasks.add(task);
            Ui.speak("Understood. This task hath been added to thy list:\n" + task);
        } else if (commandType == Command.DEADLINE) {
            String[] params = message.split(" /");
            Task task;
            try {
                task = new Deadline(params[0].substring(9), params[1].substring(3));
            } catch (DateTimeParseException e) {
                Ui.speak("Your Excellency, I struggle to understand thee. To specify a date, use format\n"
                        + "yyyy-mm-dd");
                return;
            }
            tasks.add(task);
            Ui.speak("Understood. This task hath been added to thy list:\n" + task);
        } else if (commandType == Command.EVENT) {
            String[] params = message.split(" /");
            Task task;
            try {
                task = new Event(params[0].substring(6),
                        params[1].substring(5),
                        params[2].substring(3));
            } catch (DateTimeParseException e) {
                Ui.speak("Your Excellency, I struggle to understand thee. To specify a date, use format\n"
                        + "yyyy-mm-dd");
                return;
            }
            tasks.add(task);
            Ui.speak("Understood. This task hath been added to thy list:\n" + task);
        } else if (commandType == Command.FIND) {
            String keyword = message.substring(5);
            String output = "";
            for (int i = 0; i < tasks.size(); i++) {
                if (tasks.get(i).matches(keyword)) {
                    output += "\n" + (i + 1) + ". " + tasks.get(i);
                }
            }
            if (output.equals("")) {
                Ui.speak("I regret to inform thee, Your Excellency, "
                        + "that no tasks bearing this keyword exist in thy list.");
            } else {
                Ui.speak("Behold, the tasks that match thy keyword:\n" + output);
            }
        }
    }

Example from src/main/java/knight/TaskList.java lines 226-261:

    void executeCommandSilently(Command commandType, String message) {
        if (commandType == Command.TODO) {
            Task task = new ToDo(message.substring(5));
            tasks.add(task);
        } else if (commandType == Command.DEADLINE) {
            String[] params = message.split(" /");
            Task task;
            try {
                task = new Deadline(params[0].substring(9), params[1].substring(3));
            } catch (DateTimeParseException e) {
                return;
            }
            tasks.add(task);
        } else if (commandType == Command.EVENT) {
            String[] params = message.split(" /");
            Task task;
            try {
                task = new Event(params[0].substring(6),
                        params[1].substring(5),
                        params[2].substring(3));
            } catch (DateTimeParseException e) {
                return;
            }
            tasks.add(task);
        } else if (commandType == Command.MARK) {
            int index = Integer.parseInt(message.substring(5));
            Task task;

            try {
                task = tasks.get(index - 1);
            } catch (IndexOutOfBoundsException e) {
                return;
            }
            task.mark();
        }
    }

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/knight/Knight.java lines 23-27:

    /**
     * The command line interface for the program.
     *
     * @param args The command line arguments.
     */

Example from src/main/java/knight/Task.java lines 15-17:

    /**
     * Mark the task as done.
     */

Example from src/main/java/knight/Task.java lines 22-24:

    /**
     * Mark the task as not done.
     */

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 ad40cd3:


Add assertions

Add assertions to ensure program correctness

- Check that `CommandParser` works correctly.
- Check that `Event` and `Deadline` tasks cannot be successfully created with invalid time format.


  • body not wrapped at 72 characters: e.g., - Check that EventandDeadline tasks cannot be successfully created with invalid time format.

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 👍


ℹ️ 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