Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing iP code quality feedback [for @markbiju] - Round 2 #4

Open
nus-se-script opened this issue Mar 15, 2022 · 0 comments
Open

Sharing iP code quality feedback [for @markbiju] - Round 2 #4

nus-se-script opened this issue Mar 15, 2022 · 0 comments

Comments

@nus-se-script
Copy link

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

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

            boolean doneOrNot = false;

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

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

    // private String command;

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/Parser.java lines 17-70:

    public static Command parse(String fullCommand) throws DukeException {
        switch (fullCommand) {
            case "bye":
                return new ExitCommand();
            case "list":
                return new ListCommand();
            case "todo":
                throw new DukeException("Buddy!!! You gotta tell me what it is exactly you want me to add as a to-do!");
            case "deadline":
                throw new DukeException("Bud, a deadline needs a description, a date and a time yo!");
            case "event":
                throw new DukeException("Buddy you didn't tell me where your date was!!");
            default:
                String[] arrOfStr = fullCommand.split(" ", 2);
                if (arrOfStr.length > 1) {
                    String command = arrOfStr[0];
                    switch (command) {
                        case "todo":
                            return new TodoCommand(arrOfStr[1]);
                        case "deadline": {
                            String[] arrOfStr2 = arrOfStr[1].split("/", 2);
                            String[] arrOfStr3 = arrOfStr2[1].split(" ", 3);
                            return new DeadlineCommand(arrOfStr2[0], LocalDate.parse(arrOfStr3[1]), arrOfStr3[2]);
                        }
                        case "event": {
                            String[] arrOfStr2 = arrOfStr[1].split("/", 2);
                            String[] arrOfStr3 = arrOfStr2[1].split(" ", 2);
                            assert (arrOfStr3[0].equals("at")) : "event command is not entered properly.";
                            return new EventCommand(arrOfStr2[0], (" " + arrOfStr3[1]));
                        }
                        case "find":
                            return new FindCommand(arrOfStr[1]);
                        default:
                            int number = Integer.parseInt(arrOfStr[1]);
                            switch (command) {
                                case "mark":
                                    return new MarkCommand(number);
                                case "unmark":
                                    return new UnmarkCommand(number);
                                case "delete":
                                    return new DeleteCommand(number);
                                case "snooze":
                                    return new SnoozeCommand(number);
                                default:
                                throw new DukeException("Bud!!! What in the world " +
                                        "are you talking about? Are you following the right format bud?");
                                      }
                    }
                } else {
                    throw new DukeException("Bud!!! What in the world are you talking about? Are you following the" +
                            " right format bud?");
                }
        }
    }

Example from src/main/java/duke/Storage.java lines 26-79:

    public ArrayList<Task> load() throws DukeException {
        try {
            File folder = new File("data");
            File file = new File("data/tasks.txt");
            if(!folder.exists()) {
                folder.mkdir();
                if(!file.exists()) {
                    file.createNewFile();
                }
            }
            Scanner scanner = new Scanner(file);
            boolean doneOrNot = false;
            ArrayList<Task> tasks = new ArrayList<>();
            while (scanner.hasNext()) {
                String fullCommand = scanner.nextLine();
                String[] arrOfStr = fullCommand.split(" ", 5);
                String command = arrOfStr[0];
                if (Integer.parseInt(arrOfStr[2]) == 1) {
                    doneOrNot = true;
                }
                switch (command) {
                    case "D" : {
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM yyyy");
                        // split description and date/time
                        String[] arrOfStr2 = arrOfStr[4].split("\\|", 2);
                        // split within date and time
                        String[] arrOfStr3 = arrOfStr2[1].split(" ", 5);
                        assert(arrOfStr3[0].equals("")):"Error occurred in parsing";
                        // extracting date from data received
                        LocalDate by = LocalDate.parse(arrOfStr3[1] + " "
                                + arrOfStr3[2] + " " + arrOfStr3[3], formatter);
                        tasks.add(new Deadline(arrOfStr2[0], by, arrOfStr3[4], doneOrNot));
                        break;
                    }
                    case "E" : {
                        String[] arrOfStr2 = arrOfStr[4].split("\\|", 2);
                        String at = arrOfStr2[1];
                        tasks.add(new Event(arrOfStr2[0], at, doneOrNot));
                        break;
                    }
                    case "T" : {
                        tasks.add(new Todo(arrOfStr[4], doneOrNot));
                        break;
                    }
                    default : {
                        break;
                    }
                }
            }
            return tasks;
        } catch (IOException e) {
            throw new DukeException(e.getMessage());
        }
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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/DeadlineCommand.java lines 32-35:

    /**
     * Boolean indicative of whether program should end
     * @return boolean indicative of whether program should end
     */

Example from src/main/java/duke/EventCommand.java lines 29-32:

    /**
     * Boolean indicative of whether program should end
     * @return boolean indicative of whether program should end
     */

Example from src/main/java/duke/ListCommand.java lines 15-18:

    /**
     * Boolean indicative of whether program should end
     * @return boolean indicative of whether program should end
     */

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 354d8b1:

Ui.png

  • 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

Suggestion: Avoid committing binary files (e.g., *.class, *.jar, *.exe) or third-party library files in to the repo.

❗ 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 [email protected] if you want to follow up on this post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant