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

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

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

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

Comments

@soc-se-bot
Copy link

@Pinran-J 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/Duke.java lines 55-103:

    public String getResponse(String s) {
        try {
            String[] parsed = Parser.parseInput(s);
            assert parsed.length == 3 : "Parser error occurred.";

            if (parsed[0].equals("bye")) {
                return getByeResponse();

            } else if (parsed[0].equals("list")) {
                return getListResponse();

            } else if (parsed[0].equals("mark")) {
                return getMarkResponse(parseInteger(parsed[1]));

            } else if (parsed[0].equals("unmark")) {
                return getUnmarkResponse(parseInteger(parsed[1]));

            } else if (parsed[0].equals("delete")) {
                return getDeleteResponse(parseInteger(parsed[1]));

            } else if (parsed[0].equals("find")) {
                return getFindResponse(parsed[1]);

            } else if (parsed[0].equals("todo")) {
                return getTodoResponse(parsed[1]);

            } else if (parsed[0].equals("deadline")) {
                return getDeadlineResponse(parsed[1], parsed[2]);

            } else if (s.indexOf("event") == 0) {
                return getEventResponse(parsed[1], parsed[2]);

            } else {
                throw new InvalidTaskException("No valid task descriptor");
            }

        } catch (EmptyDescriptionException | InvalidTaskException
                 | InvalidFormatException e) {
            return ui.printException(e);
        } catch (DateTimeException e) {
            return ui.printErrorMessage("Error! Date format incorrect (YYYY-MM-DD HH:mm)");
        } catch (IndexOutOfBoundsException e) {
            return ui.printErrorMessage("Invalid index access detected!");
        } finally {
            assert tList != null : "TaskList has to be present";
            storage.saveFile(this.tList);
        }

    }

Example from src/main/java/duke/Parser.java lines 50-124:

    public static String[] parseInput(String s) throws InvalidTaskException,
            EmptyDescriptionException, InvalidFormatException {
        s = s.trim();
        String[] helper = s.split(" ");
        String cmd = helper[0];

        if (helper.length == 1) {
            if (cmd.equals("bye")) {
                return formatResults(cmd);

            } else if (cmd.equals("list")) {
                return formatResults(cmd);

            } else if (isValidCommand(cmd)) {
                throw new EmptyDescriptionException("Empty descriptor", cmd);
            } else {
                throw new InvalidTaskException("No valid task descriptor");
            }
        }

        if (cmd.equals("mark")) {
            if (helper.length == 2) {
                return formatResults(cmd, helper[1]);
            } else {
                throw new InvalidTaskException("No valid task descriptor");
            }
        } else if (cmd.equals("unmark")) {
            if (helper.length == 2) {
                return formatResults(cmd, helper[1]);
            } else {
                throw new InvalidTaskException("No valid task descriptor");
            }
        } else if (cmd.equals("delete")) {
            if (helper.length == 2) {
                return formatResults(cmd, helper[1]);
            } else {
                throw new InvalidTaskException("No valid task descriptor");
            }
        } else if (helper[0].equals("find")) {
            String[] findDescription = s.split(" ", 2);
            return formatResults(cmd, findDescription[1]);

        } else if (helper[0].equals("todo")) {
            String[] todoString = s.split(" ", 2);
            return formatResults(cmd, todoString[1]);

        } else if (helper[0].equals("deadline")) {
            String description = s.substring(8).trim();
            String[] temp = description.split("/by", 2);

            if (!s.contains("/by")) {
                throw new InvalidFormatException("Invalid format");
            }
            if (temp[1].trim().equals("")) {
                throw new InvalidTaskException("Invalid format");

            }
            return formatResults(cmd, temp[0].trim(), temp[1].trim());

        } else if (helper[0].equals("event")) {
            String description = s.substring(6).trim();
            String[] temp = description.split("/at", 2);

            if (!s.contains("/at")) {
                throw new InvalidFormatException("Invalid format");
            }
            if (temp[1].trim().equals("")) {
                throw new InvalidFormatException("Invalid format");
            }
            return formatResults(cmd, temp[0].trim(), temp[1].trim());

        } else {
            throw new InvalidTaskException("No valid task descriptor");
        }
    }

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/DialogBox.java lines 61-67:

    /**
     * Method that returns the DialogBox of a user.
     *
     * @param text Text to be in the DialogBox.
     * @param img Image of the user.
     * @return DialogBox to be displayed.
     */

Example from src/main/java/duke/DialogBox.java lines 72-78:

    /**
     * Method that returns the DialogBox of Duke.
     *
     * @param text Text to be in the DialogBox.
     * @param img Image of Duke.
     * @return DialogBox to be displayed.
     */

Example from src/main/java/duke/Duke.java lines 31-33:

    /**
     * Simple method that exits the Duke's run method.
     */

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)

possible problems in commit 212b578:

Updated product screenshot.

  • Not in imperative mood (?)

possible problems in commit 4b8402d:

Tweaked Duke's personality.

  • Not in imperative mood (?)

possible problems in commit fec60e5:

Changed duke image

  • Not in imperative mood (?)

Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).

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 cs2103@comp.nus.edu.sg 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