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 @inezkok] #3

Open
soc-se-script opened this issue Sep 16, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @inezkok] #3

soc-se-script opened this issue Sep 16, 2023 · 0 comments

Comments

@soc-se-script
Copy link

@inezkok 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/task/TaskCategoryComparator.java lines 18-55:

    public int compare(Task t1, Task t2) {
        String taskString = t1.toString();
        String otherTaskString = t2.toString();

        boolean isTaskToDo = taskString.startsWith("[T]");
        boolean isTaskDeadline = taskString.startsWith("[D]");
        boolean isTaskEvent = taskString.startsWith("[E]");

        boolean isOtherTaskToDo = otherTaskString.startsWith("[T]");
        boolean isOtherTaskDeadline = otherTaskString.startsWith("[D]");
        boolean isOtherTaskEvent = otherTaskString.startsWith("[E]");

        if (isTaskToDo) {
            if (isOtherTaskToDo) {
                return 0;
            } else {
                return -1;
            }
        } else if (isTaskDeadline) {
            if (isOtherTaskToDo) {
                return 1;
            } else if (isOtherTaskDeadline) {
                return 0;
            } else {
                return -1;
            }
        } else if (isTaskEvent) {
            if (isOtherTaskToDo || isOtherTaskDeadline) {
                return 1;
            } else if (isOtherTaskEvent) {
                return 0;
            } else {
                return -1;
            }
        } else {
            return 0;
        }
    }

Example from src/main/java/duke/util/Parser.java lines 33-98:

    public static Command parse(String input, int size) throws DukeException {
        assert size >= 0 : "size of task list should be more than equal to 0";

        if (input.equals("bye")) {
            return new ExitCommand();
        } else if (input.equals("list")) {
            return new ListCommand();
        } else if (input.startsWith("mark")) {
            String number = input.replaceFirst("mark", "").trim();
            checkRange(number, size);

            int index = Integer.parseInt(number);
            return new MarkDoneCommand(index);
        } else if (input.startsWith("unmark")) {
            String number = input.replaceFirst("unmark", "").trim();
            checkRange(number, size);

            int index = Integer.parseInt(number);
            return new UnmarkDoneCommand(index);
        } else if (input.startsWith("todo")) {
            String description = input.replaceFirst("todo", "").trim();
            checkToDo(description);

            return new AddToDoCommand(description);
        } else if (input.startsWith("deadline")) {
            String[] deadlineString = input.replaceFirst("deadline", "")
                    .split("/", 2);
            checkDeadline(deadlineString);

            String deadlineDate = deadlineString[1].replaceFirst("by", "").trim();
            checkDate(deadlineDate);

            String description = deadlineString[0].trim();
            LocalDate d = LocalDate.parse(deadlineDate);

            return new AddDeadlineCommand(description, d);
        } else if (input.startsWith("event")) {
            String[] eventString = input.replaceFirst("event", "").split("/", 3);
            checkEvent(eventString);

            String start = eventString[1].replaceFirst("from", "").trim();
            String end = eventString[2].replaceFirst("to", "").trim();
            checkDate(start);
            checkDate(end);

            String description = eventString[0].trim();
            LocalDate d1 = LocalDate.parse(start);
            LocalDate d2 = LocalDate.parse(end);

            return new AddEventCommand(description, d1, d2);
        } else if (input.startsWith("delete")) {
            String number = input.replaceFirst("delete", "").trim();
            checkRange(number, size);

            int index = Integer.parseInt(number);
            return new DeleteCommand(index);
        } else if (input.startsWith("find")) {
            String keyword = input.replaceFirst("find", "").trim();
            checkFind(keyword);
            return new FindCommand(keyword);
        } else if (input.equals("sort")) {
            return new SortCategoryCommand();
        } else {
            throw new DukeException("Boop Beep OOPS! I'm sorry, but I don't know what that means :(");
        }
    }

Example from src/main/java/duke/util/Storage.java lines 55-88:

    private String formatDate(String date) {
        String dateString = date;
        String month = dateString.substring(0, 3);
        String day = dateString.substring(4, 6);
        String year = dateString.substring(7, 11);

        if (month.equals("Jan")) {
            month = "01";
        } else if (month.equals("Feb")) {
            month = "02";
        } else if (month.equals("Mar")) {
            month = "03";
        } else if (month.equals("Apr")) {
            month = "04";
        } else if (month.equals("May")) {
            month = "05";
        } else if (month.equals("Jun")) {
            month = "06";
        } else if (month.equals("Jul")) {
            month = "07";
        } else if (month.equals("Aug")) {
            month = "08";
        } else if (month.equals("Sep")) {
            month = "09";
        } else if (month.equals("Oct")) {
            month = "10";
        } else if (month.equals("Nov")) {
            month = "11";
        } else if (month.equals("Dec")) {
            month = "12";
        }

        return String.format("%s-%s-%s", year, month, day);
    }

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/Parser.java lines 125-130:

    /**
     * Check whethers the user input for creating a todo is valid.
     *
     * @param description The string representation of the todo description.
     * @throws DukeException On input error.
     */

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 769ba3f:


Fixed parser checkDeadline and checkEvent methods


  • 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 👍


ℹ️ 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