Skip to content

Sharing iP code quality feedback [for @Vanessamae23] #2

@soc-se-bot-blue

Description

@soc-se-bot-blue

@Vanessamae23 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/seedu/Command.java lines 10-10:

    private boolean exit = false;

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.java lines 102-167:

    public void start(Stage stage) {

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

        // more code to be added here later
        //Step 2. Formatting the window to look as expected
        stage.setTitle("Duke Chatbot Pro");
        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);

        //Scroll down to the end every time dialogContainer's height changes.
        dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
        // more code to be added here later

        String filename = "../src/save.txt";
        new Duke(filename).run();
        boolean isExit = false;

        //Part 3. Add functionality to handle user input.
        sendButton.setOnMouseClicked((event) -> {

        });

        userInput.setOnAction((event) -> {

        });
    }

Example from src/main/java/seedu/Command.java lines 29-63:

    public ArrayList<String> execute() throws Exception {
        ArrayList<String> s = new ArrayList<>();
        try {
            if (command.equals("bye")) {
                s.add(this.ui.showByeMessage());
                this.storage.save(this.tasks);
            } else if (command.equals("list")) {
                s.add(this.ui.showTask(this.tasks));
            } else if (command.equals("delete")) {
                Task removed = this.tasks.remove(this.index);
                s.add(this.ui.removeTask(removed, this.tasks.getLen()));
            } else if (command.equals("mark")) {
                this.tasks.mark(this.index);
                s.add(this.ui.showMarked());
            } else if (command.startsWith("find")) {
                String keyword = command.substring(4).trim();
                ArrayList<Task> foundWords = this.tasks.find(keyword);
                s.add(this.ui.showFoundWords(foundWords));
            } else if (command.startsWith("remove")) {
                String keyword = command.substring(6).trim();
                ArrayList<Task> foundTasks = this.tasks.find(keyword);
                ArrayList<Task> removedTasks = this.tasks.specificRemove(foundTasks);
                s.add(this.ui.showMassDeleteSuccess(removedTasks));
            } else {
                Task curr = new Task(command.substring(command.indexOf(" ")),
                        command.substring(0, command.indexOf(" ")));
                s.add(this.ui.addTask(curr));
                this.tasks.add(curr);
            }
        } catch (Exception e) {
            throw new Exception("Some error occurred " + e.getMessage());
        }
        return s;

    }

Example from src/main/java/seedu/Task.java lines 16-64:

    public Task(String description, String category) throws IllegalArgumentException {
        this.isDone = false;
        if (category.equals("todo")) {
            this.category = Type.ToDo;
            String[] splitWord =description.split(" ", 2);
            try {
                this.title = splitWord[1].trim();
                this.description = splitWord[0].trim() + " " + title;
            } catch(Exception e) {
                throw new IllegalArgumentException("Please correct the format");
            }
        } else if (category.equals("deadline")) {
            this.category = Type.Deadline;
            String[] splitWord =description.split("/", 4);
            try {
                if (splitWord.length == 2) {
                    this.title = splitWord[0].trim();
                    this.end = splitWord[1].split("by ")[1].trim();
                    this.description = title + "("+ splitWord[1].split("by ")[1].trim() + ")";
                } else {
                    String date = splitWord[1].substring( 3).length() == 1 ? "0"
                            + splitWord[1].substring( 3) : splitWord[1].substring( 3);

                    String endDate = splitWord[3]+"-"+splitWord[2]+"-" + date;
                    String formattedDate = LocalDate.parse(endDate)
                            .format(DateTimeFormatter.ofPattern("MMM d yyyy"));
                    this.title = splitWord[0];
                    this.end = formattedDate;
                    this.description = splitWord[0] + "("+ formattedDate + ")";
                }
            } catch(Exception e) {
                throw new IllegalArgumentException("Please correct the format");
            }

        } else if (category.equals("event")) {
            String[] splitWord = description.split("/(from|to)", 3);
            this.category = Type.Event;
            try {
                this.title = splitWord[0].trim();
                this.start = splitWord[1].trim();
                this.end = splitWord[2].trim();
                this.description = title + "(From : " + start + " To : " + end + ")";
            } catch(Exception e) {
                throw new IllegalArgumentException("Please correct the format");
            }
        } else {
            throw new IllegalArgumentException("OOPS!!! I'm sorry, but I don't know what that means :-(");
        }
    }

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.java lines 64-68:

    /**
     * Iteration 2:
     * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
     * the dialog container. Clears the user input after processing.
     */

Example from src/main/java/Duke.java lines 84-87:

    /**
     * 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/seedu/Task.java lines 13-15:

    /**
     * The task to be loaded
     */

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 2fd95d9:


Added UI image

  • Not in imperative mood (?)

possible problems in commit 766dcda:


Added better gui


  • Not in imperative mood (?)

possible problems in commit b61d46d:


Refactoring done


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