Skip to content

Sharing iP code quality feedback [for @ZhuLeYao] #1

@nus-se-script

Description

@nus-se-script

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

Example from src/main/java/Duke.java lines 27-27:

        boolean saidBye = false;

Example from src/main/java/Task.java lines 3-3:

    protected final boolean taskStatus;

Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)

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.java lines 21-138:

    public void chatDuke() {

        List<Task> allTasks = new ArrayList<>();

        this.printGreetingMessage();

        boolean saidBye = false;
        while (!saidBye) {
            String command = sc.nextLine();

            try {
                if (command.equals("list")) {
                    this.printCommandList(allTasks);
                } else if (command.startsWith("mark")) {
                    missingIndexException(command);
                    invalidIndexException(command, allTasks.size());
                    String[] str = command.split(" ");
                    int taskIndex = Integer.parseInt(str[1]) - 1;
                    Task oldTask = allTasks.get(taskIndex);
                    if (oldTask.getTaskType().equals("[T]")) {
                        Todo todo = new Todo(oldTask.getTaskNumber(),
                                true, oldTask.getTask(),
                                allTasks.size());
                        allTasks.set(taskIndex, todo);
                        todo.markAsDone();
                    } else if (oldTask.getTaskType().equals("[D]")) {
                        Deadline deadline = new Deadline(oldTask.getTaskNumber(),
                                true, oldTask.getTask(),
                                oldTask.getDeadline(), allTasks.size());
                        allTasks.set(taskIndex, deadline);
                        deadline.markAsDone();
                    } else if (oldTask.getTaskType().equals("[E]")) {
                        Event event = new Event(oldTask.getTaskNumber(),
                                true, oldTask.getTask(),
                                oldTask.getEventStartTime(),
                                oldTask.getEventEndTime(), allTasks.size());
                        allTasks.set(taskIndex, event);
                        event.markAsDone();
                    }
                } else if (command.startsWith("unmark")) {
                    missingIndexException(command);
                    invalidIndexException(command, allTasks.size());
                    String[] str = command.split(" ");
                    int taskIndex = Integer.parseInt(str[1]) - 1;
                    Task oldTask = allTasks.get(taskIndex);
                    if (oldTask.getTaskType().equals("[T]")) {
                        Todo todo = new Todo(oldTask.getTaskNumber(),
                                false, oldTask.getTask(),
                                allTasks.size());
                        allTasks.set(taskIndex, todo);
                        todo.unmarkAsUndone();
                    } else if (oldTask.getTaskType().equals("[D]")) {
                        Deadline deadline = new Deadline(oldTask.getTaskNumber(),
                                false, oldTask.getTask(),
                                oldTask.getDeadline(), allTasks.size());
                        allTasks.set(taskIndex, deadline);
                        deadline.unmarkAsUndone();
                    } else if (oldTask.getTaskType().equals("[E]")) {
                        Event event = new Event(oldTask.getTaskNumber(),
                                false, oldTask.getTask(),
                                oldTask.getEventStartTime(),
                                oldTask.getEventEndTime(), allTasks.size());
                        allTasks.set(taskIndex, event);
                        event.unmarkAsUndone();
                    }
                } else if (command.startsWith("todo")) {
                    emptyCommandException(command);
                    String[] str = command.split("todo");
                    String taskName = str[1];
                    Todo todo = new Todo(allTasks.size(), false,
                            taskName, allTasks.size() + 1);
                    allTasks.add(todo);
                    todo.printToDoTask();
                } else if (command.startsWith("deadline")) {
                    emptyCommandException(command);
                    missingTimingException(command);
                    String[] str = command.split("/by");
                    String taskName = str[0].split("deadline")[1];
                    String taskDeadline = str[1];
                    Deadline deadline = new Deadline(allTasks.size(), false,
                            taskName, taskDeadline, allTasks.size() + 1);
                    allTasks.add(deadline);
                    deadline.printDeadlineTask();
                } else if (command.startsWith("event")) {
                    emptyCommandException(command);
                    missingTimingException(command);
                    String[] str = command.split("/from");
                    String taskName = str[0].split("event")[1];
                    String[] eventStartEndTime = str[1].split("/to");
                    String eventStartTime = eventStartEndTime[0];
                    String eventEndTime = eventStartEndTime[1];
                    Event event = new Event(allTasks.size(), false,
                            taskName, eventStartTime, eventEndTime, allTasks.size() + 1);
                    allTasks.add(event);
                    event.printEventTask();
                } else if (command.startsWith("delete")) {
                    missingIndexException(command);
                    invalidIndexException(command, allTasks.size());
                    String[] str = command.split(" ");
                    int taskIndex = Integer.parseInt(str[1]) - 1;
                    Task task = allTasks.get(taskIndex);
                    task.printDelete();
                    allTasks.remove(taskIndex);
                } else if (command.equals("bye")){
                    saidBye = true;
                    this.printByeMessage();
                } else {
                    invalidCommandException(command);
                }
            } catch (DukeException d) {
                System.out.println(d.getMessage());
            } catch (NumberFormatException nfe) {
                System.out.println("\t____________________________________________________________" +
                        "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." +
                        "\n\t____________________________________________________________");
            }
        }
    }

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 👍

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