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 @rycs2812] - Round 2 #4

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

Comments

@soc-se-bot-blue
Copy link

@rycs2812 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/Command.java lines 34-86:

    public String run(String args, Duke duke) {
        String errorMessage = getUsageError(args, duke);
        if (!errorMessage.isEmpty()) {
            // If the command is used incorrectly
            return errorMessage;
        }

        switch(name) {
        case "delete":
            int index = Integer.parseInt(args) - 1;
            return duke.deleteTask(index);

        case "find":
            if (args.charAt(0) == '"' && args.charAt(args.length() - 1) == '"') {
                args = args.substring(1, args.length() - 1);
            }
            return duke.findTask(args);

        case "list":
            return duke.listTasks();

        case "deadline":
            String[] temp = args.split(" /by ", 2);
            String[] recurring = temp[1].split(" /every ", 2);
            int period = getPeriod(temp[1]);
            Task t = new Deadline(temp[0], LocalDate.parse(recurring[0].trim(),
                    DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)), period);;
            return duke.addTask(t);

        case "event":
            temp = args.split(" /at ", 2);
            recurring = temp[1].split(" /every ", 2);
            period = getPeriod(temp[1]);
            t = new Event(temp[0], LocalDate.parse(recurring[0].trim(),
                    DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)), period);
            return duke.addTask(t);

        case "todo":
            t = new ToDo(args);
            return duke.addTask(t);

        case "mark":
            // Fallthrough

        case "unmark":
            index = Integer.parseInt(args) - 1;
            boolean b = name.equals("mark");
            return duke.markTask(index, b);

        default:
            return "";
        }
    }

Example from src/main/java/duke/Command.java lines 106-222:

    private String getUsageError(String args, Duke duke) {
        TaskList taskList = duke.getTaskList();
        String usage = getCorrectUsage();
        String error = "ERROR: \n\n";
        assert taskList != null : "Task list is null";

        switch(name) {
        case "delete":
            if (args.isEmpty()) {
                return error + "Please specify a task number.\n\n" + usage;
            }
            try {
                int index = Integer.parseInt(args);
                int count = taskList.getCount();
                if (index <= 0 || index > taskList.getCount()) {
                    return error + "Please specify a valid task number. There are "
                            + count + " tasks in the list\n\n" + usage;
                }
            } catch (NumberFormatException e) {
                return error + "Please specify a task number.\n\n" + usage;
            }

            return "";

        case "find":
            if (args.isBlank()) {
                return error + "Please specify at least one keyword.\n\n" + usage;
            } else if (args.charAt(0) != '"' || args.charAt(args.length() - 1) != '"') {
                if (args.split(" ").length > 1) {
                    return error + "'find' only expects 1 argument.\n\n If there are multiple "
                            + "keywords, please enclose them in quotation marks (\"\").";
                }
            } else {
                if (args.length() == 2 || args.substring(1, args.length() - 1).isBlank()) {
                    return error + "Please specify at least one keyword.\n\n" + usage;
                }
            }
            return "";

        case "list":
            if (!args.isEmpty()) {
                return error + "'list' expects no arguments.";
            }
            return "";

        case "deadline":
            String[] temp = args.split(" /by ", 2);
            if (temp.length < 2) {
                return error + "Please specify a task and deadline.\n\n" + usage;
            } else {
                String[] recurring = temp[1].split(" /every ", 2);
                int period = getPeriod(temp[1]);
                if (period < 0) {
                    return error + "Please specify a valid period for recurring tasks.\n\n" + usage;
                } else if (period == 0) {
                    if (!isValidDate(temp[1])) {
                        return error + "Please specify the due date in the right format.\n\n" + usage;
                    }
                }
                if (!isValidDate(recurring[0])) {
                    return error + "Please specify the due date in the right format.\n\n" + usage;
                }
            }
            return "";

        case "event":
            temp = args.split(" /at ", 2);
            if (temp.length < 2) {
                return error + "Please specify an event and date.\n\n" + usage;
            } else {
                String[] recurring = temp[1].split(" /every ", 2);
                int period = getPeriod(temp[1]);
                if (period < 0) {
                    return error + "Please specify a valid period for recurring tasks.\n\n" + usage;
                } else if (period == 0) {
                    if (!isValidDate(temp[1])) {
                        return error + "Please specify the event date in the right format.\n\n" + usage;
                    }
                }
                if (!isValidDate(recurring[0])) {
                    return error + "Please specify the due date in the right format.\n\n" + usage;
                }
            }

            return "";

        case "todo":
            if (args.isEmpty()) {
                return error + "Please specify a task.\n\n" + usage;
            }
            return "";

        case "mark":
            // Fallthrough

        case "unmark":
            if (args.isEmpty()) {
                return error + "Please specify a task number\n\n" + usage;
            } else {
                try {
                    int index = Integer.parseInt(args) - 1;
                    if (index < 0 || index >= taskList.getCount()) {
                        return error + "Please specify a valid task number.\n"
                                + "There are " + taskList.getCount()
                                + " task(s) in the list.\n\n" + usage;
                    }
                } catch (NumberFormatException e) {
                    return error + "Please specify a task number.\n"
                            + "\"" + args + "\"" + " is not a task number\n\n" + usage;
                }
            }
            return "";

        default:
            return "";
        }
    }

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

No easy-to-detect issues 👍

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