Skip to content

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

@soc-se-bot

Description

@soc-se-bot

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

Example from src/main/java/Exceptions/EmptyDescriptionError.java lines 1-1:

package Exceptions;

Example from src/main/java/Exceptions/InvalidCommandError.java lines 1-1:

package Exceptions;

Suggestion: Follow the package naming convention specified by the coding standard.

Aspect: Class Name Style

No easy-to-detect issues 👍

Aspect: Dead Code

Example from src/main/java/echochat/Main.java lines 40-40:

//        DialogBox dialogBox = new DialogBox("Hello!", userImage);

Example from src/main/java/echochat/Main.java lines 41-41:

//        dialogContainer.getChildren().addAll(dialogBox);

Example from src/main/java/echochat/Parser.java lines 81-81:

//        System.out.println("by " + by);

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/echochat/Main.java lines 30-94:

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

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

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

//        DialogBox dialogBox = new DialogBox("Hello!", userImage);
//        dialogContainer.getChildren().addAll(dialogBox);

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

        scene = new Scene(mainLayout);

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

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

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

        //Handling 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/echochat/Parser.java lines 53-107:

    private Command parseTask(String type, String details) throws InvalidCommandError,EmptyDescriptionError {

        String description = "";
        String by = null;
        String from = null;
        String to = null;

        if (details.contains("/")) {
            String[] splitDetails = details.split("/");
            description = splitDetails[0].trim();

            for (int i = 1; i < splitDetails.length; i++) {
                String detail = splitDetails[i].trim();
                if (detail.startsWith("by ")) {
                    by = detail.substring(3).trim();
                } else if (detail.startsWith("from ")) {
                    from = detail.substring(5);
                } else if (detail.startsWith("to ")) {
                    to = detail.substring(3).trim();
                }
            }
        } else {
            description = details;
        }

        if (description.isEmpty()) {
            throw new EmptyDescriptionError();
        }
//        System.out.println("by " + by);
//        System.out.println("from " + from);
//        System.out.println("to " + to);


        Task task = null;
        switch (type) {
        case "todo":
            task = new Todo(description);
            break;
        case "deadline":
            if (by == null) {
                throw new InvalidCommandError();
            }
            task = new Deadline(by, description);
            break;
        case "event":
            if (to == null || from == null) {
                throw new InvalidCommandError();
            }
            task = new Event(from, to, description);
            break;
        default:
            break;
        }
        return new Command(type.equals("todo") ? CommandType.TODO : type.equals("deadline") ? CommandType.DEADLINE : CommandType.EVENT, description, 0, task);
    }

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/echochat/Deadline.java lines 28-31:

    /**
     * Get the "by" String of the deadline
     * @return String stating when deadline is
     */

Example from src/main/java/echochat/Event.java lines 32-35:

    /**
     * Get starting date of event.
     * @return String representing start of event
     */

Example from src/main/java/echochat/Event.java lines 40-43:

    /**
     * Get ending date of event.
     * @return String representing end of event
     */

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