Skip to content

Sharing iP code quality feedback [for @NicholasT1] #1

Description

@soc-se-script

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

Example from src/main/java/yapbot/commands/FindCommand.java lines 13-13:

    private boolean multiwordQuery;

Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)

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

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/yapbot/main/MainWindow.java lines 53-92:

    private void handleUserInput() {
        String input = userInput.getText();
        try {
            String response = yapBot.getResponse(input);
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getYapBotDialog(response, yapBotImage, false)
            );
        } catch (YapBotException e) {
            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getYapBotDialog(e.getMessage(), errorImage, true)
            );
        } catch (NumberFormatException e) {
            String message = "Error, Natural Language Processing Module offline...\nSpecify "
                    + "Task number instead (eg. \"1\", \"2\").";

            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getYapBotDialog(message, errorImage, true)
            );
        } catch (DateTimeParseException e) {
            String message = "Error, Dynamic DateTime Module offline."
                    + "\nDate & Time should be one of these formats:"
                    + "\n  Date & Time - \"5pm 2024/09/01\""
                    + "\n  Date Only (Time defaults to 8am) - \"2024/09/01\""
                    + "\n  Time Only (Date defaults to today) - \"5pm\"";

            dialogContainer.getChildren().addAll(
                    DialogBox.getUserDialog(input, userImage),
                    DialogBox.getYapBotDialog(message, errorImage, true)
            );
        } finally {
            userInput.clear();

            if (yapBot.shouldExit()) {
                Platform.exit();
            }
        }
    }

Example from src/main/java/yapbot/util/Storage.java lines 46-144:

    public ArrayList<Task> load() throws YapBotException {
        try {

            // Creates the file if it does not exist
            if (!file.exists()) {
                file.getParentFile().mkdirs();
                file.createNewFile();
            }

            Scanner s = new Scanner(file);
            ArrayList<Task> result = new ArrayList<>();

            while (s.hasNext()) {
                String[] taskData = s.nextLine().split("/");
                String taskType = taskData[0];

                switch (taskType) {
                case "T": {
                    int isDone = Integer.parseInt(taskData[1]);
                    String taskDetails = taskData[2];
                    Task task;

                    if (isDone == 1) {
                        task = new ToDo(taskDetails, true);
                    } else {
                        task = new ToDo(taskDetails);
                    }

                    result.add(task);
                    break;
                }

                case "D": {
                    int isDone = Integer.parseInt(taskData[1]);
                    String taskDetails = taskData[2];
                    LocalDateTime deadline = LocalDateTime.parse(taskData[3]);
                    Task task;

                    if (isDone == 1) {
                        task = new Deadline(taskDetails, deadline, true);
                    } else {
                        task = new Deadline(taskDetails, deadline, false);
                    }
                    result.add(task);
                    break;
                }

                case "E": {
                    int isDone = Integer.parseInt(taskData[1]);
                    String taskDetails = taskData[2];
                    LocalDateTime from = LocalDateTime.parse(taskData[3]);
                    LocalDateTime to = LocalDateTime.parse(taskData[4]);
                    Task task;

                    if (isDone == 1) {
                        task = new Event(taskDetails, from, to, true);
                    } else {
                        task = new Event(taskDetails, from, to, false);
                    }
                    result.add(task);
                    break;
                }

                // Handles the case where the tasktype may not exist due to file corruption
                default: {
                    this.file.delete();

                    this.file.createNewFile();

                    throw new YapBotException("Save data detected...load failed.\nCorrupted data found."
                            + "\nYapBot will execute without prior data.");
                }

                }

            }

            s.close();
            return result;
        } catch (FileNotFoundException e) {
            return new ArrayList<>();
        } catch (IOException e) {
            throw new YapBotException("Error, save file could not be created."
                    + "\nYour tasks from this session will not be saved.");
        } catch (NumberFormatException | DateTimeParseException e) {
            // Covers parsing errors due to file corruption

            this.file.delete();

            try {
                this.file.createNewFile();
            } catch (IOException ignored) {
                // IOException would have been thrown already if the file cannot be created.
            }

            throw new YapBotException("Save data detected...load failed.\nCorrupted data found."
                    + "\nYapBot will execute without prior data.");
        }
    }

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/yapbot/main/YapBot.java lines 31-33:

    /**
     * Driver function to start the YapBot instance.
     */

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

No easy-to-detect issues 👍

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