Skip to content

Sharing iP code quality feedback [for @Xzh119] - Round 2 #6

@nus-se-bot

Description

@nus-se-bot

@Xzh119 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/command/Parser.java lines 25-97:

    public static String parseCommand(String command, TaskList tasks, Ui ui) throws SamanthaException {
        if (command.equals("list") || command.equals("l")) {
            return ui.showMessage(tasks.listTasks());
        } else if (command.startsWith("mark ")) {
            int taskIndex = Integer.parseInt(command.substring(5)) - 1;
            assert taskIndex >= 0 && taskIndex < tasks.getSize() : "Invalid task index";
            tasks.markTask(taskIndex, true);
            return ui.showMessage("Nice! I've marked this task as done:\n    " + tasks.getTask(taskIndex));
        } else if (command.startsWith("m ")) {
            int taskIndex = Integer.parseInt(command.substring(2)) - 1;
            assert taskIndex >= 0 && taskIndex < tasks.getSize() : "Invalid task index";
            tasks.markTask(taskIndex, true);
            return ui.showMessage("Nice! I've marked this task as done:\n    " + tasks.getTask(taskIndex));
        } else if (command.startsWith("unmark ")) {
            int taskIndex = Integer.parseInt(command.substring(7)) - 1;
            assert taskIndex >= 0 && taskIndex < tasks.getSize() : "Invalid task index";
            tasks.markTask(taskIndex, false);
            return ui.showMessage("OK, I've marked this task as not done yet:\n    " + tasks.getTask(taskIndex));
        } else if (command.startsWith("u ")) {
            int taskIndex = Integer.parseInt(command.substring(2)) - 1;
            assert taskIndex >= 0 && taskIndex < tasks.getSize() : "Invalid task index";
            tasks.markTask(taskIndex, false);
            return ui.showMessage("OK, I've marked this task as not done yet:\n    " + tasks.getTask(taskIndex));
        } else if (command.startsWith("delete ")) {
            int taskIndex = Integer.parseInt(command.substring(7)) - 1;
            assert taskIndex >= 0 && taskIndex < tasks.getSize() : "Invalid task index";
            Task removedTask = tasks.removeTask(taskIndex);
            return ui.showMessage("OK. I've removed this task:\n    " + removedTask + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("d ")) {
            int taskIndex = Integer.parseInt(command.substring(2)) - 1;
            assert taskIndex >= 0 && taskIndex < tasks.getSize() : "Invalid task index";
            Task removedTask = tasks.removeTask(taskIndex);
            return ui.showMessage("OK. I've removed this task:\n    " + removedTask + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("todo ")) {
            assert command.length() > 5 : "Todo command must have a description";
            tasks.addTask(new Todo(command.substring(5)));
            return ui.showMessage("Got it. I've added this task:\n    " + tasks.getLastTask() + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("t ")) {
            assert command.length() > 2 : "Todo command must have a description";
            tasks.addTask(new Todo(command.substring(2)));
            return ui.showMessage("Got it. I've added this task:\n    " + tasks.getLastTask() + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("deadline ")) {
            String[] parts = command.substring(9).split(" /by ");
            assert parts.length == 2 : "Deadline command format incorrect";
            tasks.addTask(new Deadline(parts[0], parts[1]));
            return ui.showMessage("Got it. I've added this task:\n    " + tasks.getLastTask() + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("de ")) {
            String[] parts = command.substring(3).split(" /by ");
            assert parts.length == 2 : "Deadline command format incorrect";
            tasks.addTask(new Deadline(parts[0], parts[1]));
            return ui.showMessage("Got it. I've added this task:\n    " + tasks.getLastTask() + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("event ")) {
            String[] parts = command.substring(6).split(" /from | /to ");
            assert parts.length == 3 : "Event command format incorrect";
            tasks.addTask(new Event(parts[0], parts[1], parts[2]));
            return ui.showMessage("Got it. I've added this task:\n    " + tasks.getLastTask() + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        }  else if (command.startsWith("e ")) {
            String[] parts = command.substring(2).split(" /from | /to ");
            assert parts.length == 3 : "Event command format incorrect";
            tasks.addTask(new Event(parts[0], parts[1], parts[2]));
            return ui.showMessage("Got it. I've added this task:\n    " + tasks.getLastTask() + "\nNow you have " + tasks.getSize() + " tasks in the list.");
        } else if (command.startsWith("find ")) {
            String keyword = command.substring(5).trim();
            assert !keyword.isEmpty() : "Find command must have a keyword";
            return ui.showMessage(tasks.findTasks(keyword));
        } else if (command.startsWith("f ")) {
            String keyword = command.substring(2).trim();
            assert !keyword.isEmpty() : "Find command must have a keyword";
            return ui.showMessage(tasks.findTasks(keyword));
        } else {
            throw new CommandException("Your command beyond my ability.");
        }
    }

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/main/Samantha.java lines 75-79:

    /**
     * The entry point of the Samantha application.
     *
     * @param args Command-line arguments.
     */

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 Messages

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions