Skip to content

Sharing iP code quality feedback [for @Zhongli5712] - Round 2 #5

@nus-se-bot

Description

@nus-se-bot

@Zhongli5712 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/ui/Ui.java lines 44-141:

    public void start(Stage stage) throws IOException {

        //Step 1: Setting
        AnchorPane mainLayout = new AnchorPane();

        ScrollPane scrollPane = new ScrollPane();
        VBox dialogContainer = new VBox();
        scrollPane.setContent(dialogContainer);

        TextField userInput = new TextField("Type your command here");
        Button sendButton = new Button("Send");
        mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);

        //Step 2: Formatting
        double height = 600.0;
        double width = 400.0;
        stage.setMinHeight(height);
        stage.setMinWidth(width);
        stage.setResizable(false);

        mainLayout.setPrefSize(width, height);

        scrollPane.setPrefSize(width - 15, height - 65);
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);

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

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

        dialogContainer.heightProperty().addListener((observable -> {scrollPane.setVvalue(1.0);}));

        //Step 3: Handle action
        sendButton.setOnMouseClicked((event) -> {
            String userInputCommand = userInput.getText();
            Label userText = new Label(userInputCommand);
            String response = "";

            if (userInputCommand.equals("bye")) {
                userInput.clear();
                Platform.exit();
                stage.close();
            }
            try {
                Command command = bot.parse(userInputCommand);
                response = command.execute();
            } catch (DukeExceptions error) {
                response = error.getErrorMessage();
            }
            Label dukeText = new Label(response);
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(userText, new ImageView(user)),
                    DialogBox.getDukeDialog(dukeText, new ImageView(duke))
            );
            userInput.clear();
        });

        userInput.setOnAction((event) -> {
            String userInputCommand = userInput.getText();
            Label userText = new Label(userInputCommand);
            String response = "";
            if (userInputCommand.equals("bye")) {
                userInput.clear();
                Platform.exit();
                stage.close();
            }
            try {
                Command command = bot.parse(userInputCommand);
                response = command.execute();
            } catch (DukeExceptions error) {
                response = error.getErrorMessage();
            }
            Label dukeText = new Label(response);
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(userText, new ImageView(user)),
                    DialogBox.getDukeDialog(dukeText, new ImageView(duke))
            );
            userInput.clear();
        });

        Scene scene = new Scene(mainLayout);
        stage.setTitle("Duke");
        stage.setScene(scene);
        stage.show();
    }

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.

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