Skip to content

Sharing iP code quality feedback [for @hutongyan] - Round 2 #5

Description

@soc-se-bot

@hutongyan 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/core/Parser.java lines 31-86:

    public static Command parse(String command) throws BaimiException {
        assert command != null : "Command cannot be null";
        if (command.equals("bye")) {
            return new ExitCommand();
        } else if (command.equals("list")) {
            return new ListCommand();
        } else if (command.startsWith("todo ")) {
            if (command.length() <= 5) {
                throw new EmptyDescriptionException("todo");
            }
            return new AddTodoCommand(command.substring(5));
        } else if (command.startsWith("deadline ")) {
            String[] parts = command.substring(9).split(" /by ");
            if (parts.length < 2) {
                throw new InvalidFormatException("deadline [description] /by YYYY-MM-DD HHMM");
            }
            return new AddDeadlineCommand(parts[0], parts[1]);
        } else if (command.startsWith("event ")) {
            String[] parts = command.substring(6).split(" /from ");
            if (parts.length < 2) {
                throw new InvalidFormatException("event [description] /from YYYY-MM-DD HHMM /to YYYY-MM-DD HHMM");
            }
            String[] timeParts = parts[1].split(" /to ");
            if (timeParts.length < 2) {
                throw new InvalidFormatException("event [description] /from YYYY-MM-DD HHMM /to YYYY-MM-DD HHMM");
            }
            return new AddEventCommand(parts[0], timeParts[0], timeParts[1]);
        } else if (command.startsWith("mark ")) {
            int index = Integer.parseInt(command.substring(5)) - 1;  // 1-based to 0-based index
            return new MarkCommand(index);
        } else if (command.startsWith("unmark ")) {
            int index = Integer.parseInt(command.substring(7)) - 1;
            return new UnmarkCommand(index);
        } else if (command.startsWith("delete ")) {
            int index = Integer.parseInt(command.substring(7)) - 1;
            return new DeleteCommand(index);
        }  else if (command.startsWith("find ")) {
            return new FindCommand(command.substring(5));
        }  else if (command.startsWith("tag ")) {
            String[] parts = command.substring(4).split(" ");
            if (parts.length < 2) {
                throw new InvalidFormatException("tag [index] [tag]");
            }
            int index = Integer.parseInt(parts[0]) - 1;
            return new TagCommand(index, parts[1], true);
        } else if (command.startsWith("untag ")) {
            String[] parts = command.substring(6).split(" ");
            if (parts.length < 2) {
                throw new InvalidFormatException("untag [index] [tag]");
            }
            int index = Integer.parseInt(parts[0]) - 1;
            return new TagCommand(index, parts[1], false);
        } else {
            throw new UnknownCommandException();
        }
    }

Example from src/main/java/storage/Storage.java lines 41-89:

    public ArrayList<Task> load() throws BaimiException {
        ArrayList<Task> tasks = new ArrayList<>();
        File file = new File(filePath);

        if (!file.exists()) {
            return tasks;
        }

        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(" \\| ");
                if (parts.length < 3) continue;

                Task task;
                String type = parts[0];
                boolean isDone = parts[1].equals("1");
                String description = parts[2];

                 switch (type) {
                 case "T":
                    task = new Todo(description);
                    break;
                 case "D":
                     task = new Deadline(description, parts[3]);
                     break;
                 case "E":
                     task = new Event(description, parts[3], parts[4]);
                     break;
                 default:
                     continue;
                }

                if (isDone) {
                    task.markAsDone();
                }
                if (parts.length >= 4 && parts[parts.length - 1].contains(",")) {
                    String[] tagArray = parts[parts.length - 1].split(",");
                    for (String tag : tagArray) {
                        task.addTag(tag.trim());
                    }
                }
                tasks.add(task);
            }
        } catch (IOException e) {
            throw new BaimiException("Error loading tasks from file.");
        }
        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 Messages

No easy-to-detect issues 👍

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