Skip to content

Sharing iP code quality feedback [for @TiewJiaLiang] #2

@nus-se-script

Description

@nus-se-script

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

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

Example from src/main/java/wizt/ui/WizT.java lines 68-68:

                    //writeToFile(filename , tasks.getTasksList());

Example from src/main/java/wizt/ui/WizT.java lines 99-99:

        //new WizT("wizt.txt").run();

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/wizt/storage/Storage.java lines 44-86:

    public ArrayList<Task> load() throws FileNotFoundException {
        File file = new File(this.filename);
        Scanner scanner = new Scanner(file);
        ArrayList<Task> tasklists = new ArrayList<>();
        while (scanner.hasNext()) {
            String line = scanner.nextLine();
            if (line.contains("from")) {
                line = line.substring(7);
                String[] as = line.split("\\(from:");
                String[] as2 = as[1].split("to:");
                Task t = new Event(as[0].trim() + " (from: " + as2[0].trim() + " to: " + as2[1].trim());
                if (line.substring(0 , 7).contains("X")) {
                    t.markAsDone();
                }
                tasklists.add(t);
            } else {
                if (line.contains("by")) {
                    line = line.substring(7);
                    String[] as = line.split("\\(by: ");
                    String[] datetime = as[1].split(" ");
                    String date = datetime[0];
                    String time = datetime[1];
                    LocalDateTime dt = LocalDateTime.parse(date);
                    Task t = new Deadline(as[0].trim(), dt);
                    if (line.substring(0 , 7).contains("X")) {
                        t.markAsDone();
                    }
                    tasklists.add(t);
                } else {
                    Task t = new Todo(line.substring(7).trim());
                    if (line.substring(0 , 7).contains("X")) {
                        t.markAsDone();
                    }
                    tasklists.add(t);
                }
            }

        }

        return tasklists;


    }

Example from src/main/java/wizt/command/UpdateCommand.java lines 33-77:

    public String execute(TaskList tasks, Ui ui, Storage storage) {
        StringBuilder response = new StringBuilder();
        try {
            ArrayList<Task> tasklists = tasks.getTasksList();
            if (tasklists.isEmpty()) {
                response.append("\n You have no tasks in your list to update.");
                return response.toString();
            }
            if (input.contains("unmark")) {
                String[] split = input.split(" ");
                int no = Integer.parseInt(split[1]);
                assert no > 0 && no <= tasklists.size() : assertMessage;
                tasklists.get(no - 1).unmarkAsDone();
                response.append("Ok, I've marked this task as not done yet:")
                        .append(tasklists.get(no - 1).toString());

            } else {
                if (input.contains("mark")) {
                    String[] split = input.split(" ");
                    int no = Integer.parseInt(split[1]);
                    assert no > 0 && no <= tasklists.size() : assertMessage;
                    tasklists.get(no - 1).markAsDone();
                    response.append("\n Nice! I've marked this task as done:")
                            .append(tasklists.get(no - 1).toString());
                } else if (input.contains("update")) {
                    String[] split = input.split(" ");
                    if (split.length != 3) {
                        response.append("\n Please enter a valid task number and description!");
                        return response.toString();
                    }
                    int no = Integer.parseInt(split[1]);
                    String newDescription = split[2];
                    assert no > 0 && no <= tasklists.size() : assertMessage;
                    tasklists.get(no - 1).update(newDescription);
                    response.append("\n Nice! I've updated this task")
                            .append(tasklists.get(no - 1).toString());
                }

            }

        } catch (AssertionError e) {
            response.append(assertMessage);
        }
        return response.toString();
    }

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/wizt/ui/WizT.java lines 48-51:

    /**
     * The main program execution
     * @throws WizTException
     */

Example from src/main/java/wizt/ui/WizT.java lines 80-82:

    /**
     * Write to hard disk
     */

Example from src/main/java/wizt/ui/WizT.java lines 104-109:

    /**
     * Retrieve the response for a command.
     * @param fullCommand The full command entered by the user.
     * @return The response message.
     * @throws WizTException if an error occurs during command execution.
     */

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 Messages

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