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] #4

Open
soc-se-bot-red opened this issue Sep 14, 2024 · 0 comments
Open

Sharing iP code quality feedback [for @shizy] #4

soc-se-bot-red opened this issue Sep 14, 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, 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/chatbot/logic/Parser.java lines 49-179:

    public static String 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 command = inputArr[0];

        String response;

        switch (command) {
        case "bye" -> {
            response = "Bye. Hope to see you again soon!";
        }
        case "list" -> {
            response = taskList.listTasks();
        }
        case "mark" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            int idx = Integer.parseInt(inputArr[1]) - 1;
            response = taskList.mark(idx, true);
        }
        case "unmark" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            int idx = Integer.parseInt(inputArr[1]) - 1;
            response = taskList.mark(idx, false);
        }
        case "find" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            String query = inputArr[1];
            response = taskList.find(query);
        }
        case "delete" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            int idx = Integer.parseInt(inputArr[1]) - 1;
            response = taskList.remove(idx);
        }
        case "todo" -> {
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            Task newTask = new Todo(inputArr[1]);
            response = taskList.add(newTask);
        }
        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();
            }
            String name = args[0];
            String deadline = args[1];
            if (name.trim().isEmpty() || deadline.trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            try {
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
                Task newTask = new Deadline(name, LocalDateTime.parse(deadline, formatter));
                response = taskList.add(newTask);
            } catch (DateTimeParseException e) {
                response = "Error: Unable to parse datetime. Enter date time in yyyy-MM-dd HH:mm format";
            }
        }
        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();
            }

            String from = fromTo[0];
            String to = fromTo[1];

            if (name.trim().isEmpty() || from.trim().isEmpty() || to.trim().isEmpty()) {
                throw new EmptyArgsException();
            }

            try {
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
                Task newTask = new Event(name, LocalDateTime.parse(from, formatter),
                        LocalDateTime.parse(to, formatter));
                response = taskList.add(newTask);
            } catch (DateTimeParseException e) {
                response = "Error: Unable to parse datetime. Enter date time in yyyy-MM-dd HH:mm format";
            }
        }
        case "sort" -> {
            // Error handling
            if (inputArr.length == 1 || inputArr[1].trim().isEmpty()) {
                throw new EmptyArgsException();
            }
            String arg = inputArr[1].trim().toLowerCase();
            if (arg.equals("asc")) {
                response = taskList.sort(TaskList.SortOrder.ASC);
            } else if (arg.equals("desc")) {
                response = taskList.sort(TaskList.SortOrder.DESC);
            } else {
                throw new InvalidArgsException();
            }
        }
        default -> throw new InvalidCommandException();
        }

        storage.writeToFile(taskList);
        return response;
    }

Example from src/main/java/chatbot/logic/TaskList.java lines 166-208:

    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

Example from src/main/java/chatbot/Launcher.java lines 9-13:

    /**
     * Main method that serves as the entry point into the application
     *
     * @param args Irrelevant for now
     */

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 72bff45:


Add sort functionality to chatbot

Users can sort the task list with the sort command, with either the asc argument or the desc argument to sort in ascending and descending orders respectively


  • body not wrapped at 72 characters: e.g., Users can sort the task list with the sort command, with either the asc argument or the desc argument to sort in ascending and descending orders respectively

possible problems in commit 0b3d74e:


Remove unused imports

Removed unused imports from the Deadline and Event classes to fulfill checkstyle


  • body not wrapped at 72 characters: e.g., Removed unused imports from the Deadline and Event classes to fulfill checkstyle

possible problems in commit 798f42f:


Change TaskList find and listTasks implementation from for loops to streams

While this technically overcomplicates the method implementations, since for loops are simpler and sufficient for the job, this was done to review the java stream concept


  • Longer than 72 characters
  • body not wrapped at 72 characters: e.g., While this technically overcomplicates the method implementations, since for loops are simpler and sufficient for the job, this was done to review the java stream concept

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