Skip to content

Sharing iP code quality feedback [for @beetee17] #3

@soc-se-bot

Description

@soc-se-bot

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

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

    private boolean completed;

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

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/duke/DukeApp.java lines 36-97:

    public void start(Stage stage) {

        textUi = new TextUi();
        storage = new Storage(DATA_PATH);
        taskList = new TaskList(storage.load());

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

        userInput = new TextField();
        Button submitButton = new Button("Done");

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

        Scene scene = new Scene(mainLayout);

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

        submitButton.setPrefWidth(55.0);

        AnchorPane.setTopAnchor(scrollPane, 1.0);

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

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

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

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

        welcomeUser();
    }

Example from src/main/java/duke/parser/Parser.java lines 20-88:

    public static Command parse(String fullCommand) throws InvalidCommandException {
        if (fullCommand.trim().equals("bye")) {
            return new ExitCommand();
        } else if (fullCommand.trim().equals("list")) {
            return new ListTasksCommand();
        } else {
            Action action = Action.parseCommand(fullCommand);

            String contents = fullCommand.substring(action.label.length()).trim();

            try {
                switch (action) {
                case Mark:
                    return new MarkCommand(Integer.parseInt(contents) - 1);
                case Unmark:
                    return new UnmarkCommand(Integer.parseInt(contents) - 1);
                case Delete:
                    return new DeleteTaskCommand(Integer.parseInt(contents) - 1);
                case Find:
                    return new FindCommand(contents);
                case Tag:
                    String[] components = contents.split(" ");
                    if (components.length != 2 || !components[1].trim().startsWith("#")) {
                        throw new InvalidCommandException("Invalid tag command. Tag tasks with the following syntax: 'tag 1 #fun'.");
                    } else {
                        int index = Integer.parseInt(components[0]) - 1;
                        String tag = components[1].replaceAll("#", "");
                        return new TagTaskCommand(index, tag);
                    }
                case Todo:
                    if (contents.isBlank()) {
                        throw new EmptyTitleException();
                    } else {
                        return new CreateTodoCommand(new Todo(contents));
                    }
                case Deadline:
                    String[] deadlineComponents = contents.split(" /by ");

                    if (deadlineComponents.length != 2) {
                        throw new InvalidDeadlineException();
                    } else if (deadlineComponents[0].isBlank()) {
                        throw new EmptyTitleException();
                    } else {
                        return new CreateDeadlineCommand(
                                new Deadline(deadlineComponents[0].trim(),
                                        deadlineComponents[1].trim())
                        );
                    }
                case Event:
                    String[] eventComponents = contents.split(" /at ");
                    if (eventComponents.length != 2) {
                        throw new InvalidEventException();
                    } else if (eventComponents[0].isBlank()) {
                        throw new EmptyTitleException();
                    } else {
                        return new CreateEventCommand(
                                new Event(eventComponents[0].trim(),
                                        eventComponents[1].trim())
                        );
                    }
                default:
                    break;
                }
            } catch (NumberFormatException e) {
                throw new InvalidTaskIndexException();
            }
        }
        throw new InvalidCommandException("Unknown command found");
    }

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 57-61:

    /**
     * Note: You are strongly encouraged to customize the chatbot name,
     * command/display formats, and even the personality of the chatbot
     * to make your chatbot unique.
     */

Example from src/main/java/duke/commands/Command.java lines 21-23:

    /**
     * {@return true if and only if this command is the exit command}
     */

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 (Subject Only)

possible problems in commit 3d97211:

Remove dead code and replace if-else branching with switch statement for readability.

  • Longer than 72 characters

possible problems in commit 49c9a18:

Use assert feature (not JUnit assertions) to document important assumptions that should hold at various points in the code

  • Longer than 72 characters

Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).

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.

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