Skip to content

Sharing iP code quality feedback [for @nmtuan2001] #3

@soc-se-bot-blue

Description

@soc-se-bot-blue

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

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/duke/Duke.java lines 36-108:

    public String getResponse(String input) {
        String[] parsedCommands;
        Task task;
        try {
            parsedCommands = Parser.parse(input);
        } catch (DukeException e) {
            return e.getMessage();
        }
        try {
            switch (parsedCommands[0]) {
            case "list":
                return ui.showTasks(tasks);

            case "todo":
                Todo todo = new Todo(parsedCommands[1]);
                tasks.add(todo);
                return String.format("Got it. I've added this todo:\n  %s\nNow you have %d tasks in the list.",
                        todo, tasks.size());

            case "deadline":
                Deadline deadline = new Deadline(parsedCommands[1], parsedCommands[2]);
                tasks.add(deadline);
                return String.format("Got it. I've added this deadline:\n  %s\nNow you have %d tasks in the list.",
                        deadline, tasks.size());

            case "event":
                Event event = new Event(parsedCommands[1], parsedCommands[2]);
                tasks.add(event);
                return String.format("Got it. I've added this event:\n  %s\nNow you have %d tasks in the list.",
                        event, tasks.size());

            case "sort":
                tasks.sort();
                return ui.showTasks(tasks);

            case "schedule":
                return ui.viewScheduleOnDate(tasks, parsedCommands[1]);

            case "find":
                return ui.showTasks(tasks.filter(parsedCommands[1]));

            case "format":
                TimedTask.setFormat(parsedCommands[1]);
                return ui.showTasks(tasks);

            case "mark":
                task = tasks.mark(Integer.parseInt(parsedCommands[1]));
                return "Nice! I've marked this task as done:\n  " + task;

            case "unmark":
                task = tasks.unmark(Integer.parseInt(parsedCommands[1]));
                return "OK, I've marked this task as not done yet:\n  " + task;

            case "delete":
                task = tasks.delete(Integer.parseInt(parsedCommands[1]));
                return String.format("Noted. I've removed this task:\n  %s\nNow you have %d tasks in the list.",
                        task, tasks.size());

            case "bye":
                try {
                    storage.saveData(tasks);
                    return "Data is saved successfully.\nBye. Hope to see you again soon!";
                } catch (DukeException e) {
                    return e.getMessage() + "\nBye. Hope to see you again soon!";
                }

            default:
                throw new DukeException("Error encountered while processing your input.");
            }
        } catch (DukeException e) {
            return e.getMessage();
        }
    }

Example from src/main/java/duke/Storage.java lines 35-76:

    public TaskList getData() throws DukeException {
        TaskList tasks = new TaskList();
        Scanner sc;
        try {
            sc = new Scanner(file);
        } catch (FileNotFoundException e) {
            throw new DukeException("\u2639 OOPS!!! File not found: Unable to retrieve data.");
        }
        sc.useDelimiter("( \\| )|(\\n)"); // split by | or new line
        while (sc.hasNext()) {
            try {
                String type = sc.next();
                String status = sc.next();
                String description = sc.next();
                Task task;
                switch (type) {
                case "T":
                    task = new Todo(description);
                    break;
                case "D":
                    task = new Deadline(description, sc.next());
                    break;
                case "E":
                    task = new Event(description, sc.next());
                    break;
                default:
                    throw new DukeException("\u2639 OOPS!!! Invalid task type: %s", type);
                }
                if (status.equals("1")) {
                    task.markAsDone();
                } else if (!status.equals("0")) {
                    throw new DukeException("\u2639 OOPS!!! Invalid task status: %s", status);
                }
                tasks.add(task);
            } catch (NoSuchElementException e) {
                sc.close();
                throw new DukeException("\u2639 OOPS!!! File content is not in the correct format.");
            }
        }
        sc.close();
        return tasks;
    }

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/TaskList.java lines 94-98:

    /**
     * Filter tasks by keyword.
     * @param keyword Keyword to search tasks by.
     * @return List of tasks with the given keyword.
     */

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)

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