Skip to content

Sharing iP code quality feedback [for @ji-just-ji] - Round 2 #7

@soc-se-script

Description

@soc-se-script

@ji-just-ji 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

Example from src/main/java/peko/tasks/Task.java lines 13-13:

    protected boolean status;

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

Example from src/main/java/peko/DateTimeHandler.java lines 51-51:

        //return dateTimeString + " " + hour + ":" + ((min < 10) ? "0" + min : min);

Example from src/main/java/peko/Peko.java lines 46-46:

        //Application.launch(GUIController.class, args);

Example from src/main/java/peko/Peko.java lines 47-47:

        //new Peko().run();

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/peko/GUIController.java lines 60-116:

    public void start(Stage stage) {
        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();

        stage.setTitle("Peko");
        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);
        dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));

        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
            dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
            userInput.clear();
        });
        userInput.setOnAction((event) -> {
            handleUserInput();
            dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
            userInput.clear();
        });
    }

Example from src/main/java/peko/Peko.java lines 89-152:

    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();
        stage.setTitle("PekoBot");
        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);

        sendButton.setOnMouseClicked((event) -> {
            dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
            userInput.clear();
        });

        userInput.setOnAction((event) -> {
            dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
            userInput.clear();
        });
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
        });

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

Example from src/main/java/peko/tasks/TaskHandler.java lines 184-250:

    public String getResponse() {

        String out = "Gomen Peko I don't understand";
        ;
        try {

            switch (command) {
                case ECHO:
                    out = echo();
                    break;
                case LIST:
                    out = readArray();
                    break;
                case WRITE:
                    out = addToArray();
                    break;
                case MARK:
                    out = mark(description);
                    break;
                case UNMARK:
                    out = unmark(description);
                    break;
                case TODO:
                    out = todo(description);
                    break;
                case DEADLINE:
                    out = deadline(description);
                    break;
                case EVENT:
                    out = Event(description);
                    break;
                case FIND:
                    out = Find(description);
                    break;
                case DELETE:
                    out = delete(description);
                    break;
                case ARCHIVE:
                    out = archive(description);
                    break;
                case COPYPASTA:
                    try {
                        return StorageHandler.degen();
                    } catch (FileNotFoundException e) {
                        return "Hentai!";

                    } finally {
                        return "Something Went Wrong Peko....";
                    }
                case OTSUPEKO:
                    SaveHandler.saveTo();
                    return "";
                default:
                    System.out.println(out);
                    return out;
            }
        } catch (InvalidTaskException e) {
            System.out.println(e);
            return e.toString();
        } catch (NumberFormatException e) {
            out = ("That's not a number Bakatare!");

            return out;
        }
        System.out.println(out);
        return out;
    }

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/peko/Launcher.java lines 12-16:

    /**
     * The main method that launches the Peko JavaFX application.
     *
     * @param args The command-line arguments passed to the application.
     */

Example from src/main/java/peko/Peko.java lines 40-44:

    /**
     * The main entry point for the Peko application.
     *
     * @param args Command-line arguments (not used).
     */

Example from src/main/java/peko/commands/Find.java lines 32-35:

    /**
     * Private method to search for tasks that match the provided search query.
     * It populates the {@code tempTaskList} with matching tasks.
     */

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 👍


❗ 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