Skip to content

Sharing iP code quality feedback [for @ningtan11] - Round 2 #3

Description

@nus-se-bot

@ningtan11 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/seedu/duke/Parser.java lines 23-139:

    public static Command parse(String inputText) throws DukeException {
        inputText = inputText.toLowerCase();
        if (inputText.equals("bye")) {
            return new ExitCommand();
        } else if (inputText.equals("list")) {
            return new ListCommand();
        } else if (inputText.equals("coffee")) {
            return new CoffeeCommand();
        } else {
            String[] splitInput = inputText.split(" ", 2);
            if (splitInput.length == 2 && COMMANDS.contains(splitInput[0])) {
                String commandWord = splitInput[0];
                String details = splitInput[1];
                if (commandWord.equals("mark")) {
                    int index;
                    try {
                        index = Integer.parseInt(details) - 1;
                    } catch (NumberFormatException e) {
                        throw new TooManyArgumentsException("mark");
                    }
                    return new MarkCommand(index);

                } else if (commandWord.equals("unmark")) {
                    int index;
                    try {
                        index = Integer.parseInt(details) - 1;
                    } catch (NumberFormatException e) {
                        throw new TooManyArgumentsException("unmark");
                    }
                    return new UnmarkCommand(index);

                } else if (commandWord.equals("delete")) {
                    int index;
                    try {
                        index = Integer.parseInt(details) - 1;
                    } catch (NumberFormatException e) {
                        throw new TooManyArgumentsException("delete");
                    }
                    return new DeleteCommand(index);
                } else if (commandWord.equals("edit")) {
                    String[] taskDesc = details.split(" ", 3);
                    int index;
                    if (taskDesc.length < 2) {
                        throw new NotEnoughArgumentsException();
                    } else if (taskDesc.length == 2) {
                        if (taskDesc[1].equals("name")
                                || taskDesc[1].equals("time")
                                || taskDesc[1].equals("deadline")) {
                            throw new NotEnoughArgumentsException();
                        }
                        // assume description change
                        try {
                            index = Integer.parseInt(taskDesc[0]) - 1;
                        } catch (NumberFormatException e) {
                            throw new NotNumberException();
                        }

                        return new EditNameCommand(index, taskDesc[1]);
                    } else {
                        try {
                            if (taskDesc[2].length() < 2) {
                                throw new NotEnoughArgumentsException();
                            }

                            index = Integer.parseInt(taskDesc[0]) - 1;
                            if (taskDesc[1].equals("name")) {
                                return new EditNameCommand(index, taskDesc[2]);
                            } else if (taskDesc[1].equals("time") || taskDesc[1].equals("deadline")) {
                                return new EditTimeCommand(index, taskDesc[2]);
                            } else { // assume edit name
                                return new EditNameCommand(index, taskDesc[1] + " " + taskDesc[2]);
                            }
                        } catch (NumberFormatException e) {
                            throw new NotNumberException();
                        }
                    }

                } else if (commandWord.equals("todo")) {
                    if (details.length() <= 1 ) {
                        throw new NotEnoughArgumentsException();
                    }

                    return new ToDoCommand(details);

                } else if (commandWord.equals("deadline")) {
                    if (details.contains(" /by ")) {
                        String[] taskDesc = details.split(" /by ");
                        if (taskDesc[0].length() <= 1) {
                            throw new NotEnoughArgumentsException();
                        }

                        return new DeadlineCommand(taskDesc[0], taskDesc[1]);
                    } else {
                        throw new NotEnoughArgumentsException();
                    }

                } else if (commandWord.equals("event")) {
                    if (details.contains(" /on ")) {
                        String[] taskDesc = details.split(" /on ");
                        if (taskDesc[0].length() <= 1) {
                            throw new NotEnoughArgumentsException();
                        }

                            return new EventCommand(taskDesc[0], taskDesc[1]);
                    } else {
                        throw new NotEnoughArgumentsException();
                    }

                } else if (commandWord.equals("find")) {
                    return new FindCommand(details);
                }
            } else {
                throw new UnrecognisedCommandException();
            }
        }
        return null;
    }

Example from src/main/java/seedu/duke/ui/Main.java lines 45-107:

    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.
        dialogContainer.getChildren().addAll(
                DialogBox.getDukeDialog(new Label(duke.start()), new ImageView(dukeIcon))
        );
        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));
    }

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