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 @nopehax] - Round 2 #9

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

Sharing iP code quality feedback [for @nopehax] - Round 2 #9

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

Comments

@soc-se-bot-red
Copy link

@nopehax 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/task/Recurring.java lines 47-96:

    private void calculatePeriod(String input, int times) throws WrongArgumentException {
        LocalDateTime dateTime;
        LocalTime time = LocalTime.NOON;
        LocalDate date;
        if (input.contains("/at")) {
            String[] arr = input.split(" /at ");
            time = LocalTime.parse(arr[1], DateTimeFormatter.ofPattern("HHmm"));
            input = arr[0];
        }

        try {
            // recurring yearly
            date = LocalDate.parse(input, DateTimeFormatter.ofPattern("dd/MM/yy")).withYear(this.now.getYear());
            dateTime = LocalDateTime.of(date, time);
            this.period = FREQUENCY_PERIOD.yearly;
            yearly(dateTime, times);
        } catch (DateTimeException e) {
            try {
                // recurring monthly
                int n = Integer.parseInt(input);
                if (n > 31) {
                    throw new NumberFormatException();
                }
                date = LocalDate.of(this.now.getYear(), this.now.getMonth(), n);
                dateTime = LocalDateTime.of(date, time);
                this.period = FREQUENCY_PERIOD.monthly;
                monthly(dateTime, times);
            } catch (NumberFormatException f) {
                try {
                    // recurring weekly
                    LocalDate now = LocalDate.now();
                    DateTimeFormatter day = DateTimeFormatter.ofPattern("E");
                    date = now.with(TemporalAdjusters.next(DayOfWeek.from(day.parse(input))));
                    dateTime = LocalDateTime.of(date, time);
                    this.period = FREQUENCY_PERIOD.weekly;
                    weekly(dateTime, times);
                } catch (DateTimeException g) {
                    try {
                        // recurring daily
                        time = LocalTime.parse(input, Task.INPUT_TIME_FORMAT);
                        dateTime = LocalDateTime.of(this.now.toLocalDate(), time);
                        this.period = FREQUENCY_PERIOD.daily;
                        daily(dateTime, times);
                    } catch (DateTimeException h) {
                        throw new WrongArgumentException(input, f);
                    }
                }
            }
        }
    }

Example from src/main/java/duke/util/Parser.java lines 150-219:

    private void parseAddTaskCommand(ListCommands command, boolean fromSave, String... arg)
            throws NoArgumentException, WrongArgumentException, FileParseException {
        switch (command) {
        case todo:
            try {
                list.add(new ToDo(arg[0]));
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new NoArgumentException("todo", e);
            }
            break;
        case deadline:
            try {
                String[] desc = arg[0].split(" /by ");
                list.add(new Deadline(desc[0], desc[1]));
            } catch (ArrayIndexOutOfBoundsException | DateTimeParseException e) {
                if (fromSave) {
                    throw new FileParseException(command + arg[0], e);
                } else {
                    if (e instanceof ArrayIndexOutOfBoundsException) {
                        throw new NoArgumentException("deadline", e);
                    } else {
                        // e will definitely be a DateTimeParseException
                        throw new WrongArgumentException(((DateTimeParseException) e).getParsedString(), e);
                    }
                }
            }
            break;
        case event:
            try {
                String[] desc = arg[0].split(" /at ");
                list.add(new Event(desc[0], desc[1]));
            } catch (ArrayIndexOutOfBoundsException | DateTimeParseException e) {
                if (fromSave) {
                    throw new FileParseException(command + arg[0], e);
                } else {
                    if (e instanceof ArrayIndexOutOfBoundsException) {
                        throw new NoArgumentException("event", e);
                    } else {
                        //e will definitely be a DateTimeParseException
                        throw new WrongArgumentException(((DateTimeParseException) e).getParsedString(), e);
                    }
                }
            }
            break;
        case recurring:
            try {
                String[] desc = arg[0].split(" /every ");
                String[] arr = desc[1].split(" \\*");
                Recurring r = new Recurring(desc[0], arr[0], Integer.parseInt(arr[1]));
                if (fromSave) {
                    r.calculateRemaining(LocalDateTime.parse(arg[1]));
                }
                list.add(r);
            } catch (ArrayIndexOutOfBoundsException | DateTimeParseException e) {
                if (fromSave) {
                    throw new FileParseException(command + arg[0], e);
                } else {
                    if (e instanceof ArrayIndexOutOfBoundsException) {
                        throw new NoArgumentException("recurring", e);
                    } else {
                        //e will definitely be a DateTimeParseException
                        throw new WrongArgumentException(((DateTimeParseException) e).getParsedString(), e);
                    }
                }
            }
            break;
        default:
            assert false;
        }
    }

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/util/Storage.java lines 22-26:

    /**
     * To load tasks from save file.
     * @return The ArrayList containing the tasks.
     * @throws FileNotFoundException Thrown when no save file is found.
     */

Example from src/main/java/duke/util/Storage.java lines 40-43:

    /**
     * To save the current tasks into a save file.
     * @param list The TaskList object containing the list of tasks
     */

Example from src/main/java/duke/util/TaskList.java lines 57-61:

    /**
     * Method to mark a Task as done.
     * @param i The index of the task as shown in the list.
     * @return The Task that was marked done.
     */

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 7ab16d0:

Fixed issue where jar file does not work on macos and linux

  • 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