Skip to content

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

@nus-se-bot

Description

@nus-se-bot

@pwjj2000 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/duke/Duke.java lines 5-5:

//import duke.command.Command;

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

//import javafx.application.Application;

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

//import javafx.scene.control.Label;

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/Parser.java lines 40-126:

    public static Command parse(String command) throws DukeException {
        Scanner sc = new Scanner(command);

        if (sc.hasNext("mark")) {
            String mark = sc.next();
            assert (mark.equals("mark"));

            if (!sc.hasNextInt()) {
                throw new DukeException(NO_INDEX);
            } else {
                int i = sc.nextInt();
                sc.close();
                return new MarkCommand(i);
            }

        } else if (sc.hasNext("unmark")) {
            String unmark = sc.next();
            assert (unmark.equals("unmark"));
            if (!sc.hasNextInt()) {
                throw new DukeException(NO_INDEX);
            } else {
                int i = sc.nextInt();
                sc.close();
                return new UnmarkCommand(i);
            }
        } else if (sc.hasNext("deadline")) {
            sc.useDelimiter("deadline\\s*|\\s*/by\\s*");
            if (!sc.hasNext()) {
                throw new DukeException(NO_DESC_DEADLINE);
            }
            String description = sc.next();
            if (!sc.hasNext()) {
                throw new DukeException(NO_DATE_DEADLINE);
            }
            String by = sc.next();
            sc.close();
            return new AddCommand("deadline", description, by);
        } else if (sc.hasNext("event")) {
            sc.useDelimiter("event\\s*|\\s*/at\\s*");
            if (!sc.hasNext()) {
                throw new DukeException(NO_DESC_EVENT);
            }
            String description = sc.next();
            if (!sc.hasNext()) {
                throw new DukeException(NO_DATE_EVENT);
            }
            String at = sc.next();
            sc.close();
            return new AddCommand("event", description, at);
        } else if (sc.hasNext("todo")) {
            sc.useDelimiter("todo\\s*");
            if (!sc.hasNext()) {
                throw new DukeException(NO_DESC_TODO);
            }
            String description = sc.next();
            sc.close();
            return new AddCommand("todo", description, null);
        } else if (sc.hasNext("delete")) {
            sc.useDelimiter("delete\\s*");
            if (!sc.hasNextInt()) {
                throw new DukeException(NO_INDEX);
            } else {
                int i = sc.nextInt();
                sc.close();
                return new DeleteCommand(i);
            }
        } else if (sc.hasNext("find")) {
            sc.useDelimiter("find\\s*");
            if (!sc.hasNext()) {
                throw new DukeException(NO_TARGET);
            } else {
                String s = sc.next();
                sc.close();
                return new FindCommand(s);
            }
        } else if (command.equals("bye")) {
            assert (command.equals("bye"));
            sc.close();
            return new ExitCommand();
        } else if (command.equals("list")) {
            assert (command.equals("list"));
            sc.close();
            return new ShowListCommand();
        } else {
            throw new DukeException(UNKNOWN_COMMAND);
        }
    }

Example from src/main/java/duke/Storage.java lines 47-120:

    public ArrayList<Task> load() throws IOException, DukeException {
        File file = new File(filePath);
        boolean hasFile = file.exists();

        if (!hasFile) {
            this.createFile(file);
            String errorMessage = "There was an error loading your file. Starting a new list...\n";
            throw new DukeException(errorMessage);
        } else {
            System.out.println("Saved tasks retrieved!\n");
            ArrayList<Task> tasks = new ArrayList<>(100);
            Scanner sc = new Scanner(file);

            while (sc.hasNextLine()) {
                String text = sc.nextLine();
                Scanner temp = new Scanner(text);
                String filter = "\\[|\\]\\s*|by:\\s*|at:\\s*|\\s*\\(|\\s*\\)";
                temp.useDelimiter(filter);

                String taskType = temp.next();
                temp.next();
                String markStatus = temp.next();
                String description = temp.next();
                boolean isTodo = taskType.equals("T");
                boolean isDeadline = taskType.equals("D");
                boolean isEvent = taskType.equals("E");

                DateTimeFormatter inputDateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                DateTimeFormatter newDateFormat = DateTimeFormatter.ofPattern("MMM d yyyy");
                String date;
                String formattedDate;

                switch (taskType) {

                case "D":
                    assert (isDeadline);
                    temp.next();
                    date = temp.next();
                    formattedDate = inputDateFormat.format(newDateFormat.parse(date));
                    Deadline deadline = new Deadline(description, formattedDate);
                    if (isMarked(markStatus)) {
                        deadline.mark();
                    }
                    tasks.add(deadline);
                    break;

                case "E":
                    assert (isEvent);
                    temp.next();
                    date = temp.next();
                    formattedDate = inputDateFormat.format(newDateFormat.parse(date));
                    Event event = new Event(description, formattedDate);
                    if (isMarked(markStatus)) {
                        event.mark();
                    }
                    tasks.add(event);
                    break;

                case "T":
                    assert (isTodo);
                    Todo todo = new Todo(description);
                    if (isMarked(markStatus)) {
                        todo.mark();
                    }
                    tasks.add(todo);
                    break;

                default:
                    throw new DukeException("Invalid or no input read.");
                }
            }
            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

No easy-to-detect issues 👍

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