Skip to content

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

@soc-se-script

Description

@soc-se-script

@LimAiLin 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/duke/command/MarkCommand.java lines 16-16:

    private final boolean MARK;

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/duke/Storage.java lines 39-91:

    protected ArrayList<Task> load() throws IOException {
        ArrayList<Task> ls = new ArrayList<>(100);
        try {
            if (this.FILE.createNewFile()) {
                System.out.println("Dino created a new file: " + FILE.getName() + "\n");
            } else {
                BufferedReader br = new BufferedReader(new FileReader(FILE));
                try {
                    String current = br.readLine();
                    while (current != null) {
                        String[] str = current.split("\\|", 3);
                        Commands myTask = Commands.valueOf(str[0].toUpperCase(Locale.ROOT));
                        switch (myTask) {
                        case DEADLINE:
                            String[] dl = str[2].split("\\|", 2);
                            Task deadline = new Deadline(dl[0], dl[1]);
                            ls.add(deadline);
                            if (Objects.equals(str[1], "1")) {
                                deadline.markAsDone();
                            }
                            break;
                        case TODO:
                            Task todo = new ToDo(str[2]);
                            ls.add(todo);
                            if (Objects.equals(str[1], "1")) {
                                todo.markAsDone();
                            }
                            break;
                        case EVENT:
                            String[] evnt = str[2].split("\\|", 2);
                            Task event = new Event(evnt[0], evnt[1]);
                            ls.add(event);
                            if (Objects.equals(str[1], "1")) {
                                event.markAsDone();
                            }
                            break;
                        default:
                            Ui.invalidTask();
                        }
                        current = br.readLine();
                    }
                } catch (IOException | IllegalArgumentException | DukeException e) {
                    e.printStackTrace();
                }
                br.close();
                System.out.println("Dino found the file in your directory and loaded contents.\n");
            }
        } catch (IOException e) {
            System.out.println("Dino failed at creating file./n");
            e.printStackTrace();
        }
        return ls;
    }

Example from src/main/java/duke/command/AddCommand.java lines 48-95:

    public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
        Task myTask = null;
        switch(COMMAND) {
        case DEADLINE:
            String[] dl = new String[2];
            try {
                dl = STR[1].split(" /by ");
            } catch (Exception e) {
                ui.emptyDescription();
            }

            try {
                myTask = new Deadline(dl[0], dl[1]);
            } catch (Exception e) {
                ui.missingDate();
            }
            break;

        case TODO:
            try {
                myTask = new ToDo(STR[1]);
            } catch (Exception e) {
                ui.emptyDescription();
            }
            break;

        case EVENT:
            String[] evnt = new String[0];
            try {
                evnt = STR[1].split(" /at ");
            } catch (Exception e) {
                ui.emptyDescription();
            }

            try {
                myTask = new Event(evnt[0], evnt[1]);
            } catch (Exception e) {
                ui.emptyDescription();
            }
            break;
        default:
            ui.invalidTask();
            break;
        }
        tasks.add(myTask);
        storage.writeFile(tasks);
        ui.add(tasks, myTask);
    }

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/duke/Duke.java lines 51-53:

    /**
     * Main class of Duke
     */

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)

possible problems in commit dee9760:

Level-9

  • Perhaps too short (?)

possible problems in commit 4b81923:

A-JUnit

  • Perhaps too short (?)

possible problems in commit 5aa0bc6:

Merged

  • Not in imperative mood (?)
  • Perhaps too short (?)

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 👍

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