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 @pkpaing] #5

Open
soc-se-script opened this issue Feb 11, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @pkpaing] #5

soc-se-script opened this issue Feb 11, 2023 · 0 comments

Comments

@soc-se-script
Copy link

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

No easy-to-detect issues 👍

Aspect: Class Name Style

No easy-to-detect issues 👍

Aspect: Dead Code

Example from src/main/java/duke/Ui.java lines 98-98:

            //throw new duke.DukeException("OOPS!!! I'm sorry, but I don't know what that means :-(");

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/Duke.java lines 33-98:

    public void start(Stage stage) {
        String filePath = System.getProperty("user.dir") +"/data/duke.txt";
        storage = new Storage(filePath);
        tasks = new TaskList(storage.load());

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

        dialogContainer.getChildren().addAll(
                DialogBox.getDukeDialog(new Label(ui.showWelcome()), new ImageView(duke))
        );

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

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

Example from src/main/java/duke/Ui.java lines 18-101:

    public static String handleCommand(String s, TaskList t) {
        ArrayList<Task> tasks = t.getTasks();
        int numTasks = tasks.size();
        assert numTasks >= 0 : "Number of tasks should be a positive number";
        assert s.length() >= 0 : "Number of letters in a command should be a positive number";
        // user enters list command
        if (s.contains("list")) {
            return t.displayTasks();

            // user enters mark or unmark command
        } else if (s.contains("mark") || s.contains("unmark")) {
            int taskNumber = Integer.parseInt(s.substring(s.length() - 1)) - 1;
            tasks.get(taskNumber).toggleMarked();
            String output = "";
            if (s.contains("unmark")) {
                output += "    OK, I've marked this task as not done yet:";
            } else {
                output += "    Nice! I've marked this task as done:";
            }
            return output + "  " + tasks.get(taskNumber).toString();

            // user enters a new task
        } else if (s.contains("todo")) {
            if (s.substring(4).isBlank()) {
                return "    OOPS!!! The description of a todo cannot be empty.";
            } else {
                Task newTask = new Todo(s.substring(5));
                tasks.add(newTask);
                return "    added: " + newTask;
            }

        } else if (s.contains("deadline")) {
            if (s.substring(8).isBlank()) {
                return "    OOPS!!! The description of a deadline cannot be empty.";
            } else {
                String by = s.substring(s.indexOf("/") + 4);
                Task newTask = new Deadline(s.substring(9, s.indexOf("/") - 1), by);
                tasks.add(newTask);
                return "    added: " + newTask;
            }

        } else if (s.contains("event")) {
            if (s.substring(5).isBlank()) {
                return "    OOPS!!! The description of a event cannot be empty.";
            } else {
                String from = s.substring(s.indexOf("/") + 6, s.lastIndexOf("/") - 1);
                String to = s.substring(s.lastIndexOf("/") + 4);
                Task newTask = new Event(s.substring(6, s.indexOf("/") - 1), from, to);
                tasks.add(newTask);
                return "    added: " + newTask;
            }

        } else if (s.contains("delete")) {
            if (s.substring(6).isBlank()) {
                return "    OOPS!!! You have not entered anything to delete.";
            } else {
                int taskNumber = Integer.parseInt(s.substring(s.length() - 1)) - 1;
                Task deletedTask = tasks.get(taskNumber);
                tasks.remove(taskNumber);
                return "    Noted. I've removed this task:\n      " + deletedTask +
                        "\n    Now you have " + tasks.size()+ " tasks in the list";

            }
        } else if (s.contains("find")) {
            String findString = s.substring(5);
            ArrayList<Task> foundTasks = new ArrayList<Task>();
            for (Task task : tasks) {
                if (task.toString().contains(findString)) {
                    foundTasks.add(task);
                }
            }
            TaskList searchResults = new TaskList(foundTasks);
            return "Here are the tasks I found!\n" + searchResults.displayTasks();

            // make displayTasks return a String
        } else if (s.contains("sort")) {
            return t.displaySorted();
        } else if (s.contains("bye")) {
            return "    Bye. Hope to see you soon!";
        } else {
            //throw new duke.DukeException("OOPS!!! I'm sorry, but I don't know what that means :-(");
            return "    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/Duke.java lines 99-104:

    /**
     * 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 112-116:

    /**
     * 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/Duke.java lines 133-136:

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

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

Added Sort command which sorts the displayed task based on whether it's a Todo, Deadline or Event

  • Not in imperative mood (?)
  • Longer than 72 characters

possible problems in commit 6225d45:

Added assertions into several class files

  • Not in imperative mood (?)

possible problems in commit 84905c6:

Merged Level-10 and A-CheckStyle into Master

  • 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