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

Open
nus-se-script opened this issue Oct 11, 2022 · 0 comments
Open

Comments

@nus-se-script
Copy link

@pratham31012002 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/pluto/Parser.java lines 50-98:

    public static Command parse(String inputLine) throws PlutoException {

        isOnlyCommand(inputLine.toLowerCase());
        String[] textArr = inputLine.split("\\s+", 2);
        assert textArr.length != 0 : "textArr shouldn't be empty";
        String command = textArr[0].strip();
        Type enumCommand;
        try {
            enumCommand = Type.valueOf(command.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new PlutoException("OOPS!!! I don't know what that means!");
        }
        switch (enumCommand) {
        case TODO:
            assert textArr.length == 2 : "textArr should have length 2";
            return parseAddTask(textArr[1].strip(), Type.TODO);
        case DEADLINE:
            assert textArr.length == 2 : "textArr should have length 2";
            return parseAddTask(textArr[1].strip(), Type.DEADLINE);
        case EVENT:
            assert textArr.length == 2 : "textArr should have length 2";
            return parseAddTask(textArr[1].strip(), Type.EVENT);
        case MARK:
            assert textArr.length == 2 : "textArr should have length 2";
            return new UpdateStatusCommand(parseIdx(textArr[1]), true);
        case UNMARK:
            assert textArr.length == 2 : "textArr should have length 2";
            return new UpdateStatusCommand(parseIdx(textArr[1]), false);
        case DELETE:
            assert textArr.length == 2 : "textArr should have length 2";
            return new DeleteCommand(parseIdx(textArr[1]));
        case LIST:
            return new ListCommand();
        case SHOW:
            assert textArr.length == 2 : "textArr should have length 2";
            return new ShowCommand(parseDateOnly(textArr[1]));
        case FIND:
            assert textArr.length == 2 : "textArr should have length 2";
            return new FindCommand(textArr[1]);
        case RESCHEDULE:
            return parseRescheduleTask(textArr[1].strip());
        case HELP:
            return new HelpCommand();
        case BYE:
            return new ExitCommand();
        default:
            throw new PlutoException("OOPS!!! I don't know what that means!");
        }
    }

Example from src/main/java/pluto/Storage.java lines 55-100:

    public ArrayList<Task> load() throws PlutoException {
        ArrayList<Task> missions = new ArrayList<>();
        try {
            Scanner sc = new Scanner(file);
            while (sc.hasNext()) {
                String text = sc.nextLine().strip();
                String[] textArr = text.split("\\s+\\|\\s+", 3);
                assert textArr.length != 0 : "textArr shouldn't be empty";
                String command = textArr[0];
                assert textArr.length == 3 : "textArr should have 3 elements";
                int lastPipe = textArr[2].lastIndexOf("|");
                String date = null;
                String description = null;
                if (lastPipe != -1) {
                    date = textArr[2].substring(lastPipe + 1).strip();
                    description = textArr[2].substring(0, lastPipe).strip();
                }
                switch (command) {
                case "T":
                    Task todo = new Todo(textArr[2]);
                    markTasks(todo, textArr[1]);
                    missions.add(todo);
                    break;
                case "D":
                    assert date != null : "Deadline date cannot be null";
                    assert description != null : "Deadline description cannot be null";
                    Task deadline = new Deadline(description, Parser.parseDate(date));
                    markTasks(deadline, textArr[1]);
                    missions.add(deadline);
                    break;
                case "E":
                    assert date != null : "Event date cannot be null";
                    assert description != null : "Event description cannot be null";
                    Task event = new Event(description, Parser.parseDate(date));
                    markTasks(event, textArr[1]);
                    missions.add(event);
                    break;
                default:
                    throw new PlutoException("OOPS!!! Couldn't parse previous tasks.");
                }
            }
        } catch (IOException e) {
            throw new PlutoException("OOPS!!! " + e.getMessage());
        }
        return missions;
    }

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/pluto/task/Task.java lines 41-43:

    /**
     * Mark a task as done.
     */

Example from src/main/java/pluto/task/Task.java lines 48-50:

    /**
     * Unmark a task.
     */

Example from src/main/java/pluto/task/Task.java lines 91-95:

    /**
     * Check if all keywords are in the task description.
     * @param keywords Array of keywords.
     * @return If all keywords are present in task description.
     */

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 👍

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