Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing iP code quality feedback [for @remuslum] #6

Open
nus-se-bot opened this issue Sep 16, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @remuslum] #6

nus-se-bot opened this issue Sep 16, 2023 · 0 comments

Comments

@nus-se-bot
Copy link

@remuslum 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 9-9:

    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

Example from src/main/java/duke/Parser.java lines 122-123:

        }
        else {

Example from src/main/java/duke/command/FindCommand.java lines 35-36:

        }
        else {

Example from src/main/java/duke/command/MarkCommand.java lines 30-31:

            }
            else {

Suggestion: As specified by the coding standard, use egyptian style braces.

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/Duke.java lines 91-145:

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

        sendButton.setOnMouseClicked((event) -> {
            handleUserInput();
        });

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

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

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

Example from src/main/java/duke/Parser.java lines 22-126:

    public Command parse(String command) throws DukeException {
        if (command.contains("bye")) {
            if (command.trim().length() != 3) {
                throw new DukeException(ErrorMessages.INVALID_INPUT.getMessage() + " 'bye' ?");
            } else {
                return new ExitCommand();
            }
        } else if (command.contains("list")){
            if (command.trim().length() != 4) {
                throw new DukeException(ErrorMessages.INVALID_INPUT.getMessage() + " 'list' ?");
            } else {
                return new ListCommand();
            }
        } else if (command.contains("delete")) {
            if (command.trim().length() == 6) {
                throw new DukeException(ErrorMessages.MISSING_TASK_NUMBER.getMessage());
            } else {
                int deleteNumber = Integer.parseInt(command.substring(7));
                assert deleteNumber > 0 : "Not Valid Number";
                return new DeleteCommand(deleteNumber);
            }
        } else if (command.contains("todo")) {
            if (command.trim().length() == 4) {
                throw new DukeException(ErrorMessages.EMPTY_DESCRIPTION_HEAD.getMessage() + "todo"
                        + ErrorMessages.EMPTY_DESCRIPTION_TAIL.getMessage());
            } else {
                Todo toDoTask = new Todo(command.substring(5));
                return new AddCommand(toDoTask);
            }
        } else if (command.contains("deadline")) {
            if (command.trim().length() == 8) {
                throw new DukeException(ErrorMessages.EMPTY_DESCRIPTION_HEAD.getMessage() +
                        "deadline" + ErrorMessages.EMPTY_DESCRIPTION_TAIL.getMessage());
            } else {
                String[] deadlineString = command.substring(9).split("/");
                if (deadlineString.length == 1) {
                    // Check if deadline is present.
                    throw new DukeException(ErrorMessages.MISSING_DEADLINE.getMessage());
                } else {
                    // Deal with DateTimeParseException
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Messages.DATE_FORMAT.getMessage());
                    LocalDateTime deadlineDate = LocalDateTime.parse(deadlineString[1].substring(3),
                            formatter);
                    Deadline deadlineTask = new Deadline(deadlineString[0].trim(), deadlineDate);
                    return new AddCommand(deadlineTask);
                }
            }
        } else if (command.contains("event")) {
            if (command.trim().length() == 5) {
                throw new DukeException(ErrorMessages.EMPTY_DESCRIPTION_HEAD.getMessage() + "event" +
                        ErrorMessages.EMPTY_DESCRIPTION_TAIL.getMessage());
            } else {
                String[] eventString = command.substring(6).split("/");
                // Check if a start and end time has been provided.
                if (eventString.length < 3) {
                    throw new DukeException(ErrorMessages.MISSING_EVENT_TIMING.getMessage());
                } else if (eventString.length > 3) {
                    throw new DukeException(ErrorMessages.TOO_MANY_EVENT_TIMINGS.getMessage());
                } else {
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Messages.DATE_FORMAT.getMessage());
                    LocalDateTime startDate = LocalDateTime.parse(eventString[1].substring(5).trim(), formatter);
                    LocalDateTime endDate = LocalDateTime.parse(eventString[2].substring(3).trim(), formatter);
                    if (endDate.isBefore(startDate)) {
                        throw new DukeException(ErrorMessages.INVALID_END_DATE.getMessage());
                    } else {
                        Event eventTask = new Event(eventString[0].trim(), startDate, endDate);
                        return new AddCommand(eventTask);
                    }
                }
            }
        } else if (command.contains("mark") && !command.contains("unmark")) {
            if (command.trim().length() == 4) {
                throw new DukeException(ErrorMessages.MISSING_TASK_NUMBER.getMessage());
            } else {
                int taskNumber = Integer.parseInt(command.substring(5).trim());
                assert taskNumber > 0 : "Not Valid Number";
                return new MarkCommand(taskNumber);
            }
        } else if (command.contains("unmark")) {
            if (command.trim().length() == 6) {
                throw new DukeException(ErrorMessages.MISSING_TASK_NUMBER.getMessage());
            } else {
                int taskNumber = Integer.parseInt(command.substring(7).trim());
                assert taskNumber > 0 : "Not Valid Number";
                return new UnmarkCommand(taskNumber);
            }
        } else if (command.contains("find")) {
            if (command.trim().length() == 4) {
                throw new DukeException(ErrorMessages.NO_KEYWORD_PROVIDED.getMessage());
            } else {
                String input = command.substring(5).trim();
                return new FindCommand(input);
            }
        } else if (command.contains("help")){
            if (command.trim().length() == 4){
                return new HelpCommand(0);
            } else {
                int helpNumber = Integer.parseInt(command.substring(5));
                return new HelpCommand(helpNumber);
            }
        }
        else {
            throw new DukeException(ErrorMessages.INCOMPREHENSIBLE_TASK.getMessage());
        }
    }

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 147-152:

    /**
     * Iteration 1:
     * Creates a label with the specified text and adds it to the dialog container.
     * @param text String containing text to add
     * @return a label with the specified text that has word wrap enabled.
     */

Example from src/main/java/duke/Duke.java lines 176-179:

    /**
     * You should have your own function to generate a response to user input.
     * Replace this stub with your completed method.
     */

Example from src/main/java/duke/Storage.java lines 43-48:

    /**
     * At the end of the session, the textfile is properly updated.
     * @param taskList the final task list before ending the session
     * @param filePath the path of the updated textfile
     * @throws DukeException if the filepath is incorrectly inputted
     */

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

possible problems in commit ed87d1b:


Code currently violates several coding quality standards
This affects the readability of the code and cause possible confusion.
As such, thw code has been modified such that class names, variables names all provide meanings and if-else statements are modified such that the main body is obvious to the reader.


  • No blank line between subject and body
  • body not wrapped at 72 characters: e.g., As such, thw code has been modified such that class names, variables names all provide meanings and if-else statements are modified such that the main body is obvious to the reader.

possible problems in commit 7f1b638:


Modified code to make main path obvious


  • Not in imperative mood (?)

possible problems in commit 72ea5d1:


Added Help Command and test cases for it


  • Not in imperative mood (?)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant