Skip to content

Sharing iP code quality feedback [for @jiewei98] #3

@nus-se-bot

Description

@nus-se-bot

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

Example from src/main/java/Duke/Storage.java lines 110-111:

        }
        catch (IOException e) {

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

Example from src/main/java/Duke/Main.java lines 34-34:

        //System.out.println("For debugging: stop() method called!");

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/Duke/Duke.java lines 39-100:

    public void start(Stage stage) {
        //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);
        assert scene != null : "Unable to load GUI";

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

        //Part 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/Storage.java lines 47-90:

    public ArrayList<Task> load() {
        ArrayList<Task> list = new ArrayList<>(); // init arraylist

        try {
            FileReader fr = new FileReader(this.filePath.toString());
            BufferedReader br = new BufferedReader(fr);
            StringBuffer sb = new StringBuffer();
            String currLine;

            while ((currLine = br.readLine()) != null) {
                int taskInt = currLine.indexOf("[") + 1;
                char typeOfTask = currLine.charAt(taskInt);
                int doneInt = taskInt + 3;
                char taskDone = currLine.charAt(doneInt);
                String task = currLine.substring(doneInt + 3);
                if (typeOfTask == 'T') {
                    ToDo toDo = new ToDo(task);
                    if (taskDone == 'X') {
                        toDo.complete();
                    }
                    list.add(toDo);
                } else if (typeOfTask == 'D') {
                    int start = task.indexOf(":");
                    String date = task.substring((start + 2), (task.length() - 1));
                    Deadline deadline = new Deadline(task.substring(0, start - 4), date);
                    if (taskDone == 'X') {
                        deadline.complete();
                    }
                    list.add(deadline);
                } else if (typeOfTask == 'E') {
                    int start = task.indexOf(":");
                    String date = task.substring((start + 2), (task.length() - 1));
                    Event event = new Event(task.substring(0, start - 4), date);
                    if (taskDone == 'X') {
                        event.complete();
                    }
                    list.add(event);
                }
            }
        } catch (IOException e) {
            System.out.println("An error occurred.");
        }
        return list;
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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/CommandList.java lines 53-58:

    /**
     * List all Tasks.
     *
     * @param list Arraylist of Tasks to manipulate
     * @return String output of all tasks
     */

Example from src/main/java/Duke/CommandList.java lines 69-77:

    /**
     * Mark/unmark a specified Task.
     *
     * @param list Arraylist of Tasks to manipulate
     * @param inputs Array of String from user's input
     * @param firstWord First word from user's input
     * @param storage Storage object to load/store list of Tasks
     * @return String output of whether a task is marked/unmarked
     */

Example from src/main/java/Task/Task.java lines 20-24:

    /**
     * Get status of Task.
     *
     * @return a "X" if Task is done and " " if otherwise
     */

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)

No easy-to-detect issues 👍

ℹ️ The bot account @nus-se-bot 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