Skip to content

Sharing iP code quality feedback [for @vishandi] #19

@nus-se-bot

Description

@nus-se-bot

@vishandi 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/duke/Duke.java lines 95-179:

    public String processUserInput(String userInput) {
        assert userInput != null;
        String[] userInputs = userInput.split(" ");
        String command = userInputs[0];
        String response;
        try {
            switch (command) {
            case "bye":
                if (userInput.equals("bye")) {
                    response = Duke.BYE;
                    return response;
                } else {
                    throw DukeException.DukeInvalidCommand();
                }

            case "list":
                if (userInput.equals("list")) {
                    response = this.taskList.toString();
                    return response;
                } else {
                    throw DukeException.DukeInvalidCommand();
                }

            case "mark":
                try {
                    int index = Integer.parseInt(userInput.substring(MARK_LENGTH)) - 1;
                    response = this.taskList.markTaskAsDone(index);
                    writeTasks();
                    return response;
                } catch (NumberFormatException e) {
                    throw DukeException.DukeInvalidIndex();
                } catch (IndexOutOfBoundsException e) {
                    throw DukeException.DukeInvalidIndex();
                } catch (DukeException d) {
                    throw d;
                }

            case "unmark":
                try {
                    int index = Integer.parseInt(userInput.substring(UNMARK_LENGTH)) - 1;
                    response = this.taskList.unmarkTaskAsDone(index);
                    writeTasks();
                    return response;
                } catch (NumberFormatException e) {
                    throw DukeException.DukeInvalidIndex();
                } catch (IndexOutOfBoundsException e) {
                    throw DukeException.DukeInvalidIndex();
                } catch (DukeException d) {
                    throw d;
                }

            case "delete":
                try {
                    int index = Integer.parseInt(userInput.substring(DELETE_LENGTH)) - 1;
                    response = this.taskList.deleteTaskAtIndex(index);
                    writeTasks();
                    return response;
                } catch (IndexOutOfBoundsException e) {
                    throw DukeException.DukeInvalidIndex();
                }

            case "find":
                try {
                    ArrayList<Task> matchingTasks = this.parser.findTasksByKeyword(userInput,
                            this.taskList.getTasks());
                    response = this.ui.getMatchingTasksMessage(matchingTasks);
                    return response;
                } catch (DukeException d) {
                    throw d;
                }

            default:
                Task task = this.parser.parseTaskFromUi(command, userInput);
                if (this.parser.isDuplicate(task, this.taskList.getTasks())) {
                    throw DukeException.DukeDuplicate();
                }
                response = this.taskList.addTask(task);
                writeTasks();
                return response;
            }
        } catch (DukeException d) {
             response = this.ui.getErrorMessage(d);
             return response;
        }
    }

Example from src/main/java/parser/Parser.java lines 40-90:

    public Task parseTaskFromUi(String command, String userInput) throws DukeException {
        assert command != null && userInput != null;
        switch (command) {
        case "todo":
            try {
                String description = userInput.split(" ", 2)[1];
                description = description.trim();
                if (description.equals("")) {
                    throw DukeException.DukeDescriptionEmpty();
                }
                return new Todo(description);
            } catch (IndexOutOfBoundsException e) {
                throw DukeException.DukeDescriptionEmpty();
            } catch (DukeException d) {
                throw DukeException.DukeDescriptionEmpty();
            }

        case "deadline":
            try {
                String[] descriptionAndTime = userInput.substring(9).split(" /by ");
                String description = descriptionAndTime[0].trim();
                if (description.equals("")) {
                    throw DukeException.DukeDescriptionEmpty();
                }
                LocalDate deadlineTime = LocalDate.parse(descriptionAndTime[1].trim());
                return new Deadline(description, deadlineTime);
            } catch (DukeException d) {
                throw DukeException.DukeDescriptionEmpty();
            } catch (Exception e) {
                throw DukeException.DukeInvalidCommand();
            }

        case "event":
            try {
                String[] descriptionAndTime = userInput.substring(6).split(" /at ");
                String description = descriptionAndTime[0].trim();
                if (description.equals("")) {
                    throw DukeException.DukeDescriptionEmpty();
                }
                LocalDate eventTime = LocalDate.parse(descriptionAndTime[1].trim());
                return new Event(description, eventTime);
            } catch (DukeException d) {
                throw DukeException.DukeDescriptionEmpty();
            } catch (Exception e) {
                throw DukeException.DukeInvalidCommand();
            }

        default:
            throw DukeException.DukeInvalidCommand();
        }
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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 49-53:

    /**
     * The main logic of the process of Duke.
     * @param args
     * @throws DukeException
     */

Example from src/main/java/duke/Duke.java lines 60-64:

    /**
     * Initialize Duke by reading from the default file.
     * Greet Users.
     * @throws DukeException
     */

Example from src/main/java/duke/Duke.java lines 69-71:

    /**
     * The main process of how Duke runs.
     */

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 👍

ℹ️ The bot account @nus-se-bot used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact cs2103@comp.nus.edu.sg if you want to follow up on this post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions