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

Open
soc-se-bot-red opened this issue Feb 17, 2024 · 0 comments
Open

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

soc-se-bot-red opened this issue Feb 17, 2024 · 0 comments

Comments

@soc-se-bot-red
Copy link

@AidenLYT 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/filestorage/Storage.java lines 22-22:

        // throw new AssertionError("Constructor is not allowed");

Example from src/main/java/parser/Parser.java lines 30-30:

        // throw new AssertionError("Constructor is not allowed");

Example from src/main/java/parser/Parser.java lines 101-101:

            // assert false : "Invalid command";

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/Taylor.java lines 42-121:

    public void start(Stage stage) {
        //Step 1. Setting up required components
        for (int i = 0; i < 3; i++) {
            tasksList.add(new ArrayList<>());
        }

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

        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) -> {
            dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
            userInput.clear();
        });

        userInput.setOnAction((event) -> {
            dialogContainer.getChildren().add(getDialogLabel(userInput.getText()));
            userInput.clear();
        });

        //Scroll down to the end every time dialogContainer's height changes.
        dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
        try {
            tasksList = Storage.inputFromFile(tasksList);
            initialiseTasksList();
        } catch (Exception e) {
            dialogContainer.getChildren().addAll(
                    DialogBox.getDukeDialog(e.toString(), wrio)
            );
        }
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput(stage);
        });

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

Example from src/main/java/parser/Parser.java lines 39-106:

    public static String executeCommand(String input, List<List<Task>> tasksList) {
        String response = null;

        int splitFirstWhitespace = 2;
        String[] userInputSplit = input.split(" ", splitFirstWhitespace);

        int actionIdx = 0;
        String actionCalled = userInputSplit[actionIdx];
        Commands cmd = getCommands(actionCalled);

        // Switch between different calls
        switch (cmd) {
        case BYE:
            try {
                response = Storage.outputToFile(tasksList);
            } catch (Exception err) {
                response = Ui.printError(err);
            }
            break;
        case LIST:
            response = ListTask.execListTask(tasksList);
            break;
        case MARK:
        case UNMARK:
            try {
                response = MarkTask.execMarkTask(input, tasksList);
            } catch (TaylorException err) {
                response = Ui.printError(err);
            }

            break;
        case TODO:
        case DEADLINE:
        case EVENT:
            try {
                response = InsertTask.execInsertTask(input, tasksList);
            } catch (TaylorException err) {
                response = Ui.printError(err);
            }
            break;
        case DELETE:
            try {
                response = DeleteTask.execDeleteTask(input, tasksList);
            } catch (TaylorException err) {
                response = Ui.printError(err);
            }
            break;
        case SEARCH:
            try {
                response = SearchTask.execSearchTask(input, tasksList);
            } catch (TaylorException err) {
                response = Ui.printError(err);
            }
            break;
        case FIND:
            try {
                response = FindTask.exec(input, tasksList);
            } catch (TaylorException err) {
                response = Ui.printError(err);
            }
            break;
        default:
            // assert false : "Invalid command";
            response = Ui.invalidCommand();
            break;
        }
        return response;
    }

Example from src/main/java/tasklist/DeleteTask.java lines 29-79:

    public static String execDeleteTask(String input, List<List<Task>> taskList) throws TaylorException {
        StringBuilder response = new StringBuilder();
        String[] wordPartition = input.split(" ");
        try {
            int idxToGetTaskType = 1;
            String taskType = wordPartition[idxToGetTaskType].toUpperCase();
            boolean isEvent = taskType.equals("EVENT");
            boolean isDeadline = taskType.equals("DEADLINE");
            boolean isTodo = taskType.equals("TODO");
            if (!isTodo && !isDeadline && !isEvent) {
                throw new TaylorException("<TaskType> only accepts EVENT/DEADLINE/TODO");
            }

            int idxToGetTaskNo = 2;
            int noToDelete = Integer.parseInt(wordPartition[idxToGetTaskNo]);

            List<? extends Task> listToEdit = new ArrayList<>();
            String editList = null;
            if (isDeadline) {
                int deadlineListIdx = 0;
                listToEdit = taskList.get(deadlineListIdx);
                editList = "Deadline";
            } else if (isEvent) {
                int eventListIdx = 1;
                listToEdit = taskList.get(eventListIdx);
                editList = "Event";
            } else if (isTodo) {
                int todoListIdx = 2;
                listToEdit = taskList.get(todoListIdx);
                editList = "ToDo";
            } else {
                assert false : "Program should not run here";
            }

            if (noToDelete < 0 || noToDelete > listToEdit.size()) {
                throw new TaylorException("Invalid task number");
            }

            int idx = noToDelete - 1;
            Task taskRemoved = listToEdit.get(idx);
            listToEdit.remove(idx);
            response.append("Noted. I've removed this tasks:\n");
            response.append(taskRemoved).append("\n");
            response.append("Now you have ").append(listToEdit.size())
                    .append(" tasks in the ").append(editList).append("list.\n");

        } catch (ArrayIndexOutOfBoundsException | NumberFormatException err) {
            throw new TaylorException("Please ensure the following format: DELETE <TaskType> <TaskNumber>");
        }
        return response.toString();
    }

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/Taylor.java lines 123-128:

    /**
     * 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/Taylor.java lines 137-141:

    /**
     * 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/Taylor.java lines 158-161:

    /**
     * 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

possible problems in commit d8f4762:


Merge remote-tracking branch 'origin'
Merge with PR from other branches


  • No blank line between subject and body

possible problems in commit 5ebdfed:


Improved Code Quality


  • Not in imperative mood (?)

Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).

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