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 @Ramanathan0908] #4

Open
soc-se-bot-blue opened this issue Sep 10, 2022 · 0 comments
Open

Sharing iP code quality feedback [for @Ramanathan0908] #4

soc-se-bot-blue opened this issue Sep 10, 2022 · 0 comments

Comments

@soc-se-bot-blue
Copy link

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

Example from src/main/java/duke/dukeExceptions/DukeException.java lines 1-1:

package duke.dukeExceptions;

Suggestion: Follow the package naming convention specified by the coding standard.

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 38-104:

    public void start(Stage stage) {
        try {
            taskList = new TaskList();
            storage = new Storage(taskList);
            parser = new Parser();
        } catch (DukeException e) {
            return;
        }
        
        //Step 1. Setting up required components
        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.
        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));
    }

Example from src/main/java/duke/Parser.java lines 26-130:

    public String parseInput(String input, TaskList taskList) throws DukeException {
        String[] tokens = input.split(" ", 2);
        String command = tokens[0];
        String arguments = tokens.length == 2 ? tokens[1] : null;

        switch (command) {
        case "bye":
            return "exit";
        case "list":
            return taskList.toString();
        case "todo": {
            if (arguments == null) {
                throw new DukeException("Todo description cannot be empty");
            }
            Task newTask = new ToDo(arguments.trim());
            taskList.addTask(newTask);
            return "I've added: " + newTask + " you have " + taskList.getTaskListSize() + " duke.tasks left";
        }
        case "deadline": {
            if (arguments == null) {
                throw new DukeException("Deadline description cannot be empty");
            }

            String[] deadlineArgs = arguments.split("/by", 2);
            if (deadlineArgs.length == 1) {
                throw new DukeException("Deadline requires a /by date");
            }
            System.out.println(deadlineArgs[1]);
            Task newTask = new Deadline(deadlineArgs[0].trim(), deadlineArgs[1].trim());
            taskList.addTask(newTask);
            return "I've added: " + newTask + " you have " + taskList.getTaskListSize() + " tasks left";
        }
        case "event": {
            if (arguments == null) {
                throw new DukeException("Event description cannot be empty");
            }

            String[] deadlineArgs = arguments.split("/at", 2);
            if (deadlineArgs.length == 1) {
                throw new DukeException("Event requires a /at date");
            }

            Task newTask = new Event(deadlineArgs[0].trim(), deadlineArgs[1].trim());
            taskList.addTask(newTask);
            return "I've added: " + newTask + " you have " + taskList.getTaskListSize() + " tasks left";
        }
        case "mark": {
            try {
                if (arguments == null) {
                    throw new DukeException("Please enter a valid task number");
                }
                int taskNo = Integer.parseInt(arguments) - 1;
                Task taskTobeMarked = taskList.getTask(taskNo);
                taskTobeMarked.markDone();
                return "I have marked: " + taskTobeMarked + " as done";
            } catch (NumberFormatException | IndexOutOfBoundsException e) {
                throw new DukeException("Please enter a valid task number");
            }
        }
        case "unmark": {
            try {
                if (arguments == null) {
                    throw new DukeException("Please enter a valid task number");
                }
                int taskNo = Integer.parseInt(arguments) - 1;
                Task taskTobeMarked = taskList.getTask(taskNo);
                taskTobeMarked.markNotDone();
                return "I have marked: " + taskTobeMarked + " as not done";
            } catch (NumberFormatException | IndexOutOfBoundsException e) {
                throw new DukeException("Please enter a valid task number");
            }
        }
        case "delete": {
            try {
                if (arguments == null) {
                    throw new DukeException("Please enter a valid task number");
                }
                int taskNo = Integer.parseInt(arguments) - 1;
                Task taskTobeDeleted = taskList.getTask(taskNo);
                taskList.removeTask(taskNo);
                return "I have deleted: " + taskTobeDeleted;
            } catch (NumberFormatException | IndexOutOfBoundsException e) {
                throw new DukeException("Please enter a valid task number");
            }
        }
        case "find": {
            if (arguments == null) {
                throw new DukeException("Please enter a keyword to search");
            }
            TaskList matchingTasks = new TaskList();
            for (int i = 0; i < taskList.getTaskListSize(); i++) {
                if (taskList.getTask(i).containsKeyword(arguments.trim())) {
                    matchingTasks.addTask(taskList.getTask(i));
                }
            }
            return "Here are your matching tasks:\n" + matchingTasks.toString();
        }
        case "sort": {
            taskList.sort();
            return taskList.toString();
        }
        default:
            return "I don't know that command please enter a valid command";
        }
    }

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 128-131:

    /**
     * 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/TaskList.java lines 23-27:

    /**
     * Add Task to the TaskList.
     * 
     * @param t The Task to be added.
     */

Example from src/main/java/duke/tasks/Task.java lines 25-27:

    /**
     * Mark the Task as done.
     */

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

resolved merge conflicts

  • Not in imperative mood (?)

possible problems in commit f6e4270:

added assertions to document important assumptions

  • 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