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 @Derekljh] #1

Open
nus-se-bot opened this issue Feb 17, 2024 · 0 comments
Open

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

nus-se-bot opened this issue Feb 17, 2024 · 0 comments

Comments

@nus-se-bot
Copy link

@Derekljh 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/Duke.java lines 73-133:

    public void start(Stage stage) {
        //Step 1. Setting up required components

        //The container for the content of the chat to scroll.
        scrollPane = new ScrollPane();
        dialogContainer = new VBox();
        scrollPane.setContent(dialogContainer);

        userInput = new TextField();
        sendButton = new Button("Send");

        AnchorPane mainLayout = new AnchorPane();
        mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);

        scene = new Scene(mainLayout);

        stage.setScene(scene);
        stage.show();

        //Step 2. Formatting the window to look as expected
        stage.setTitle("Duke");
        stage.setResizable(false);
        stage.setMinHeight(600.0);
        stage.setMinWidth(400.0);

        mainLayout.setPrefSize(400.0, 600.0);

        scrollPane.setPrefSize(385, 535);
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);

        scrollPane.setVvalue(1.0);
        scrollPane.setFitToWidth(true);

        //You will need to import `javafx.scene.layout.Region` for this.
        dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);

        userInput.setPrefWidth(325.0);

        sendButton.setPrefWidth(55.0);

        AnchorPane.setTopAnchor(scrollPane, 1.0);

        AnchorPane.setBottomAnchor(sendButton, 1.0);
        AnchorPane.setRightAnchor(sendButton, 1.0);

        AnchorPane.setLeftAnchor(userInput , 1.0);
        AnchorPane.setBottomAnchor(userInput, 1.0);

        //Step 3. Add functionality to handle user input.
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
        });

        userInput.setOnAction((event) -> {
            handleUserInput();
        });

        //Scroll down to the end every time dialogContainer's height changes.
        dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
    }

Example from src/main/java/duke/Parser.java lines 36-113:

    public static void parseCommand(String input, TaskList taskList, Ui ui) throws DukeException {
        Command category = Command.getCategory(input);
        int listSize = taskList.getSize();
        switch (category) {
            case BYE:
                break;
            case LIST:
                taskList.listTask(ui);
                break;
            case UNMARK:
                int unmarkId = ui.readInt() - 1;
                if (unmarkId < 0 || unmarkId >= listSize) {
                    try {
                        ui.setIndentedLine();
                        throw new DukeException("Sorry, " +
                                "please select a valid task for me to unmark!");
                    } catch (DukeException e) {
                        System.out.println("  " + e.getMessage());
                        ui.setIndentedLine();
                        return;
                    }
                }
                taskList.unmarkTask(unmarkId, ui);
                break;
            case MARK:
                int markId = ui.readInt() - 1;
                if (markId < 0 || markId >= listSize) {
                    try {
                        ui.setIndentedLine();
                        throw new DukeException("Sorry, " +
                                "please select a valid task for me to mark!");
                    } catch (DukeException e) {
                        System.out.println("  " + e.getMessage());
                        ui.setIndentedLine();
                        return;
                    }
                }
                taskList.markTask(markId, ui);
                break;
            case DELETE:
                int deleteId = ui.readInt() - 1;
                if (deleteId < 0 || deleteId >= listSize) {
                    try {
                        ui.setIndentedLine();
                        throw new DukeException("Sorry, " +
                                "please select a valid task for me to delete!");
                    } catch (DukeException e) {
                        System.out.println("  " + e.getMessage());
                        ui.setIndentedLine();
                        return;
                    }
                }
                taskList.deleteTask(deleteId, ui);
                ui.listSizeMessage(taskList);
                break;
            case TODO:
                parseToDo(taskList, ui);
                break;
            case DEADLINE:
                parseDeadline(taskList, ui);
                break;
            case EVENT:
                parseEvent(taskList, ui);
                break;
            case FIND:
                String findDescription = ui.readCommandLine();
                ArrayList<Task> matchedTasks = taskList.find(findDescription);
                taskList.listMatchedTasks(matchedTasks, ui);
            default:
                try {
                    ui.setIndentedLine();
                    throw new DukeException("Sorry, I cannot understand what this is!");
                } catch (DukeException e) {
                    System.out.println("  " + e.getMessage());
                    ui.setIndentedLine();
                }
        }
    }

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/Duke.java lines 135-140:

    /**
     * Iteration 1:
     * Creates a label with the specified text and adds it to the dialog container.
     * @param text String containing text to add
     * @return a label with the specified text that has word wrap enabled.
     */

Example from src/main/java/duke/Duke.java lines 149-153:

    /**
     * Iteration 2:
     * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
     * the dialog container. Clears the user input after processing.
     */

Example from src/main/java/duke/task/Task.java lines 28-32:

    /**
     * Method to mark or unmark task.
     *
     * @return "X" if marking task, " " if unmarking task.
     */

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

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