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

Open
soc-se-bot-red opened this issue Oct 15, 2024 · 0 comments
Open

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

soc-se-bot-red opened this issue Oct 15, 2024 · 0 comments

Comments

@soc-se-bot-red
Copy link

@shizy 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/chatbot/logic/Parser.java lines 64-159:

    public static Command processInput(String s, TaskList taskList, Storage storage) throws InputException {
        // splits the command into 2 strings - The command string, and the arguments string
        String[] inputArr = s.split(" ", 2);
        String commandStr = inputArr[0];

        Command command;

        switch (commandStr) {
        case "bye" -> {
            command = new MessageCommand("Bye. Hope to see you again soon!");
        }
        case "list" -> {
            command = new ListCommand(taskList);
        }
        case "mark" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            command = new MarkCommand(taskList, Integer.parseInt(inputArr[1]), true);
        }
        case "unmark" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            command = new MarkCommand(taskList, Integer.parseInt(inputArr[1]), false);
        }
        case "find" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            command = new FindCommand(taskList, inputArr[1].trim());
        }
        case "delete" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            command = new RemoveCommand(taskList, Integer.parseInt(inputArr[1]));
        }
        case "todo" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            command = new TodoCommand(taskList, inputArr[1]);
        }
        case "deadline" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            if (!inputArr[1].contains("/by ")) {
                throw new MissingDeadlineByException();
            }
            String[] args = inputArr[1].split(" /by ", 2);
            if (args.length <= 1) {
                throw new DeadlineArgsException();
            }
            command = new DeadlineCommand(taskList, args[0], args[1]);
        }
        case "event" -> {
            // Error handling
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            if (!inputArr[1].contains("/from ")) {
                throw new MissingEventFromException();
            }
            if (!inputArr[1].contains(" /to")) {
                throw new MissingEventToException();
            }
            String[] args = inputArr[1].split(" /from ", 2);
            if (args.length <= 1) {
                throw new EventArgsException();
            }

            String name = args[0];
            String[] fromTo = args[1].split(" /to ", 2);
            if (fromTo.length <= 1) {
                throw new EventArgsException();
            }

            command = new EventCommand(taskList, name, fromTo[0], fromTo[1]);
        }
        case "sort" -> {
            // Error handling
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }

            String arg = inputArr[1].trim().toLowerCase();
            command = new SortCommand(taskList, arg);
        }
        default -> throw new InvalidCommandException();
        }

        storage.writeToFile(taskList);
        return command;
    }

Example from src/main/java/chatbot/logic/TaskList.java lines 171-213:

    public String sort(SortOrder order) {
        if (order == SortOrder.ASC) {
            this.tasks.sort((t1, t2) -> {
                if ((t1 instanceof TimeTask newT1) && (t2 instanceof TimeTask newT2)) {
                    if (newT2.getTime().isBefore(newT1.getTime())) {
                        return 1; // move t2 up in the list
                    } else if (newT1.getTime().isBefore(newT2.getTime())) {
                        return -1; // move t1 up in the list
                    } else {
                        return 0; // order can stay the same
                    }
                } else if (t1 instanceof TimeTask) { // t2 is not a TimeTask
                    return 1; // move t2 up in the list
                } else if (t2 instanceof TimeTask) {
                    return -1; // move t1 up in the list
                } else {
                    return 0; // order can stay the same
                }
            });
            return "List has been sorted in ascending order!";
        } else if (order == SortOrder.DESC) {
            this.tasks.sort((t1, t2) -> {
                if ((t1 instanceof TimeTask newT1) && (t2 instanceof TimeTask newT2)) {
                    if (newT2.getTime().isBefore(newT1.getTime())) {
                        return -1; // move t1 up the list
                    } else if (newT1.getTime().isBefore(newT2.getTime())) {
                        return 1; // move t2 up the list
                    } else {
                        return 0; // order can stay the same
                    }
                } else if (t1 instanceof TimeTask) { // t2 is not a TimeTask
                    return 1; // move t2 up in the list
                } else if (t2 instanceof TimeTask) {
                    return -1; // move t1 up in the list
                } else {
                    return 0; // order can stay the same
                }
            });
            return "List has been sorted in descending order!";
        } else {
            return "Invalid ordering!"; // this line should be unreachable
        }
    }

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

No easy-to-detect issues 👍

Aspect: Recent Git Commit Message

possible problems in commit 938eb5a:


Replace UI screenshot for User Guide

Updated UI screenshot to be consistent with the current version of the program


  • body not wrapped at 72 characters: e.g., Updated UI screenshot to be consistent with the current version of the program

possible problems in commit 88d3e7a:


Add screenshot and user guide to README

README is meant for the users to understand the use cases and commands present in the program


  • body not wrapped at 72 characters: e.g., README is meant for the users to understand the use cases and commands present in the program

possible problems in commit dba5dfd:


Refactor Parser to utilise Command subclasses

The Command class and its subclasses hide the command execution logic from the Parser class. This helps to declutter the processInput() function in the Parser class


  • body not wrapped at 72 characters: e.g., The Command class and its subclasses hide the command execution logic from the Parser class. This helps to declutter the processInput() function in the Parser class

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