Skip to content

Sharing iP code quality feedback [for @chloeelim] - Round 2 #8

Description

@nus-se-bot

@chloeelim 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/gui/MainWindow.java lines 67-116:

    private void handleUserInput() {
        String input = userInput.getText();
        Response response = duke.reply(input);
        ResponseType responseType = response.getResponseType();

        if (responseType.equals(ResponseType.LIST) || responseType.equals(ResponseType.TASK)) {
            LinkedList<HBox> tasklistItemDialogs = new LinkedList<>();
            String replyMessage = response.getResponseMessage();

            if (responseType.equals(ResponseType.LIST)) {
                TaskList tasklist = (TaskList) response.getResponseObject();
                tasklistItemDialogs = tasklist.transform((Task t, Integer i) ->
                        TaskListItemDialog.getTaskListItemDialog(t, i)
                );
            } else {
                Task task = (Task) response.getResponseObject();
                tasklistItemDialogs.push(TaskListItemDialog.getTaskListItemDialog(task, null));
            }

            tasklistItemDialogs.push(DialogBox.getDukeDialog(replyMessage, studiousDukeImage));
            tasklistItemDialogs.push(DialogBox.getUserDialog(input, userImage));
            dialogContainer.getChildren().addAll(tasklistItemDialogs);
        } else if (responseType.equals(ResponseType.STAT)) {
            String replyMessage = response.getResponseMessage();
            Node stat = (Node) response.getResponseObject();
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getDukeDialog(replyMessage, dukeStarImage),
                    stat
            );
        } else if (responseType.equals(ResponseType.ERROR)) {
            String replyMessage = response.getResponseMessage();
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getDukeDialog(replyMessage, dukeErrorImage)
            );
        } else {
            String replyMessage = response.getResponseMessage();
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getDukeDialog(replyMessage, dukeImage)
            );
        }
        userInput.clear();

        if (response.getResponseType() == ResponseType.QUIT) {
            userInput.setDisable(true);
            sendButton.setDisable(true);
        }
    }

Example from src/test/java/ViewScheduleCommandTest.java lines 20-70:

    public void executeViewSchedule_noDateSpecifiedHasTask_success() throws DukeException {
        TaskList taskList = new TaskList();
        Storage storage = new Storage("data", "duke.txt");

        // to do task not completed should be on schedule
        ToDo toDoNotCompleted = new ToDo("incomplete");
        // to do task completed should not be on schedule
        ToDo toDoCompleted = new ToDo("completed", true, LocalDateTime.now());
        // deadline task not completed with a due date that's over should be on schedule
        Deadline deadlineNotCompletedOverdue = new Deadline("overdue", LocalDateTime.now().minusDays(2));
        // deadline task completed with a due date that's over should not be on schedule
        Deadline deadlineCompletedPastDue = new Deadline("completed past due",
                LocalDateTime.now().minusDays(2), true, LocalDateTime.now());
        // deadline task completed with a due date on the queried date should still be on schedule
        Deadline deadlineCompletedDueCurrent = new Deadline("completed due present",
                LocalDateTime.now(), true, LocalDateTime.now());
        // event task that's over but not marked done should be on schedule
        Event eventOverNotDone = new Event("overdue", LocalDateTime.now().minusDays(2),
                LocalDateTime.now().minusDays(2));
        // event task that's in the future and not done should not be on schedule
        Event eventNotOverNotDone = new Event("in future", LocalDateTime.now().plusDays(2),
                LocalDateTime.now().plusDays(2));
        // event task that's happening now should be on schedule
        Event eventHappeningNow = new Event("now", LocalDateTime.now().minusDays(2),
                LocalDateTime.now().plusDays(2), true, LocalDateTime.now());

        taskList.addTask(toDoNotCompleted);
        taskList.addTask(toDoCompleted);
        taskList.addTask(deadlineNotCompletedOverdue);
        taskList.addTask(deadlineCompletedPastDue);
        taskList.addTask(deadlineCompletedDueCurrent);
        taskList.addTask(eventOverNotDone);
        taskList.addTask(eventNotOverNotDone);
        taskList.addTask(eventHappeningNow);

        ViewScheduleCommand viewScheduleCommand = new ViewScheduleCommand("");
        Response<TaskList> viewScheduleResponse = viewScheduleCommand.execute(taskList, storage);
        String expectedResponseMessage = String.format("let's see... you have 5 tasks on your schedule on %s,"
                + " let's get to work! [_(`▿´)_]", LocalDate.now());

        assertEquals(ResponseType.LIST, viewScheduleResponse.getResponseType());
        assertEquals(expectedResponseMessage, viewScheduleResponse.getResponseMessage());

        TaskList responseTaskList = viewScheduleResponse.getResponseObject();
        assertEquals(5, responseTaskList.size());
        assertEquals(toDoNotCompleted, responseTaskList.getTask(1));
        assertEquals(deadlineNotCompletedOverdue, responseTaskList.getTask(2));
        assertEquals(deadlineCompletedDueCurrent, responseTaskList.getTask(3));
        assertEquals(eventOverNotDone, responseTaskList.getTask(4));
        assertEquals(eventHappeningNow, responseTaskList.getTask(5));
    }

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/date/TextDateFormat.java lines 19-21:

    /**
     * {@inheritDoc}
     */

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)

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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