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 @quelinxiao] - Round 2 #4

Open
soc-se-script opened this issue Mar 19, 2024 · 0 comments
Open

Comments

@soc-se-script
Copy link

@quelinxiao We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

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/bob/Parser.java lines 78-79:

        catch (IndexOutOfBoundsException e) {

Example from src/main/java/bob/Parser.java lines 99-100:

        catch (IndexOutOfBoundsException e) {

Example from src/main/java/bob/Parser.java lines 124-125:

        catch (DateTimeParseException 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

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/bob/Bob.java lines 55-93:

    public void run() {
        ui.showGreetMessage();

        Scanner scanner = new Scanner(System.in);
        TaskList taskList = tasks;

        while (true) {
            String input = scanner.nextLine();

            if (input.equals("bye")) {
                parser.parseExit(storage, tasks);
                break;
            } else if (input.equals("list")) {
                parser.parseList(taskList);
            } else if (input.equals("clear")) {
                parser.parseClear(taskList);
            } else if (input.trim().matches("mark|unmark|deadline|todo|event|delete")) {
                ui.showIncompleteEntryMessage();
            } else if (input.startsWith("mark ")) {
                parser.parseMark(input, taskList);
            } else if (input.startsWith("unmark ")) {
                parser.parseUnmark(input, taskList);
            } else if (input.startsWith("deadline ")) {
                parser.parseDeadline(input, taskList);
            } else if (input.startsWith("todo ")) {
                parser.parseTodo(input, taskList);
            } else if (input.startsWith("event ")) {
                parser.parseEvent(input, taskList);
            } else if (input.startsWith("delete ")) {
                parser.parseDelete(input, taskList);
            } else if (input.startsWith("find ")) {
                parser.parseFind(input, taskList);
            } else {
                ui.showUnknownCommandMessage();
            }
        }

        scanner.close();
    }

Example from src/main/java/bob/Bob.java lines 100-160:

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

        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/bob/Storage.java lines 25-87:

    public TaskList loadFile() {
        TaskList taskList = new TaskList();

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;

            while ((line = reader.readLine()) != null) {
                String[] parts = line.split("\\|");

                String taskType = parts[0].trim();
                boolean isDone = parts[1].trim().equals("1");
                String taskDescription = parts[2].trim();

                Task task;

                if (taskType.equals("T")) {
                    task = new ToDo(taskDescription);
                }

                else if (taskType.equals("D")) {
                    String deadlineDate = parts[3].trim();
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm");
                    LocalDateTime dateTime = LocalDateTime.parse(deadlineDate, formatter);
                    task = new Deadline(taskDescription, dateTime);
                }

                else if (taskType.equals("E")) {
                    String fromDate = parts[3].trim();
                    String toDate = parts[4].trim();

                    task = new Event(taskDescription, fromDate, toDate);
                }

                else {
                    throw new IllegalStateException("Unexpected value: " + taskType);
                }

                if (isDone) {
                    task.markAsDone();
                }

                taskList.addTask(task);
            }
        }

        catch (FileNotFoundException e) {
            File data = new File("data");
            data.mkdir();
            File tasks = new File(data, "tasks.txt");
            try {
                tasks.createNewFile();
            }
            catch (IOException x) {
                System.out.println(x.getMessage());
            }
        }

        catch (IOException e) {
            System.out.println(e.getMessage());
        }
        System.out.println("File loaded.");
        return taskList;
    }

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/bob/Bob.java lines 52-54:

    /**
     * A method that signals the chatbot to start its processes.
     */

Example from src/main/java/bob/Bob.java lines 162-167:

    /**
     * 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/bob/Bob.java lines 175-179:

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

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


Change gradle build to use Launcher as main class

Main class was set to Bob so the GUI would not work

Changing main class to Launcher allows it to be the entry point of the application


  • body not wrapped at 72 characters: e.g., Changing main class to Launcher allows it to be the entry point of the application

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 👍


❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality 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