Skip to content

Sharing iP code quality feedback [for @ReaganTan00] - Round 2 #4

@nus-se-bot

Description

@nus-se-bot

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

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/duke/util/Storage.java lines 36-110:

    public void readStorage(Response response) throws IOException {
        try {
            File file = new File(filePath);
            FileReader fr = new FileReader(file.getPath());
            BufferedReader br = new BufferedReader(fr);
            String line = br.readLine();
            if (line == null) {
                response.append("Your task list is empty.");
            } else {
                assert line != null : "Line read is empty";
                response.append("These are the tasks you had previously:\n");
                while (line != null) {
                    String[] segments = line.split(">");
                    switch (segments[0]) {
                    case "T":
                        assert segments.length == 4 : "A todo task follows the format 'todo task'";
                        tasks.createTaskSilently(new Todo(segments[2]));
                        if (segments[1].equals("X")) {
                            tasks.getTask(tasks.getSize() - 1).setDone();
                        }
                        if (segments[3].startsWith("#")) {
                            tasks.getTask(tasks.getSize() - 1).setTag(segments[3]);
                        }
                        break;

                    case "E":
                        assert segments.length == 5 : "An event task follows the format 'event task /at YYYY-MM-DD'";
                        String time = segments[3];
                        LocalDate date = LocalDate.parse(time);
                        tasks.createTaskSilently(new Event(segments[2], date));
                        if (segments[1].equals("X")) {
                            tasks.getTask(tasks.getSize() - 1).setDone();
                        }
                        if (segments[4].startsWith("#")) {
                            tasks.getTask(tasks.getSize() - 1).setTag(segments[4]);
                        }
                        break;

                    case "D":
                        assert segments.length == 5
                                : "A deadline task follows the format 'deadline task /by YYYY-MM-DD'";
                        String time2 = segments[3];
                        LocalDate date2 = LocalDate.parse(time2);
                        tasks.createTaskSilently(new Deadline(segments[2], date2));
                        if (segments[1].equals("X")) {
                            tasks.getTask(tasks.getSize() - 1).setDone();
                        }
                        if (segments[4].startsWith("#")) {
                            tasks.getTask(tasks.getSize() - 1).setTag(segments[4]);
                        }
                        break;

                    default:
                        break;

                    }
                    line = br.readLine();
                }
            }
            for (int i = 0; i < tasks.getSize(); i++) {
                response.append("  " + (i + 1) + ": " + tasks.getTask(i) + "\n");
            }
            br.close();
        } catch (FileNotFoundException e) {
            if (new File("data").mkdir()) {
                response.append("Directory for a save file does not exist, creating one for you.\n");
                response.append("Creating a save file for you (duke.txt)");
                new File("data/duke.txt").createNewFile();
            } else if (new File("data/duke.txt").createNewFile()) {
                response.append("Save file does not exist, creating one for you.");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

No easy-to-detect issues 👍

Aspect: Recent Git Commit Message (Subject Only)

possible problems in commit 96e5526:

Cleaned up merge formatting to pass checkstyle

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

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

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