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 @reneeyeow02] - Round 2 #5

Open
nus-se-bot opened this issue Oct 11, 2022 · 0 comments
Open

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

nus-se-bot opened this issue Oct 11, 2022 · 0 comments

Comments

@nus-se-bot
Copy link

@reneeyeow02 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/meowmeow/Parser.java lines 19-108:

    public static Command parse(String userInput) {

        userInput = userInput.trim();
        String[] splitUI = userInput.split(" ");
        assert splitUI.length > 0 : "splitUI should not be empty";
        switch (splitUI[0]) {

        case "hi":
            return new HiCommand();

        case "list":
            return new ListCommand();

        case "bye":
            return new ExitCommand();

        case "undo":
            return new UndoCommand();

        default:
            break;
        }

        String[] splitUserInput = userInput.split(" ", 2);

        String cmdWord = splitUserInput[0];

        switch (cmdWord) {
        case "mark":
            try {
                int taskNum = Integer.parseInt(splitUserInput[1]);
                return new MarkCommand(true, taskNum);
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= Meowmeow needs a number for the task you want to mark!");
            }

        case "unmark":
            try {
                int taskNum = Integer.parseInt(splitUserInput[1]);
                return new MarkCommand(false, taskNum);
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= Meowmeow needs a number for the task you want to unmark!");
            }

        case "todo":
            try {
                String taskName = splitUserInput[1];
                return new AddCommand('T', taskName);
            } catch (ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= Meowmeow needs a name for the todo you want to add!");
            }

        case "deadline":
            try {
                String nameAndLocalDateTime = splitUserInput[1];
                return new AddCommand('D', nameAndLocalDateTime);
            } catch (ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= To add a deadline type it in in this format: "
                        + "deadline (name) /by (YYYY-MM-DDTHH:MM:SS)");
            }

        case "event":
            try {
                String nameAndTime = splitUserInput[1];
                return new AddCommand('E', nameAndTime);
            } catch (ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= To add an event type it in in this format: event (name) /at (time)");
            }

        case "delete":
            try {
                int taskToDelete = Integer.parseInt(splitUserInput[1]);
                return new DeleteCommand(taskToDelete);
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= Meowmeow needs a number for the task you want to delete!");
            }

        case "find":
            try {
                String taskToFind = splitUserInput[1];
                return new FindCommand(taskToFind);
            } catch (ArrayIndexOutOfBoundsException e) {
                return new DefaultCommand("=0w0= Meowmeow needs a name for the task you want to find!");
            }

        default:
            return new DefaultCommand("Sowwie meowmeow doesn't understand what you said uwu ♥ \n"
                    + "Try typing something else! owo");
        }
    }

Example from src/main/java/meowmeow/Storage.java lines 60-127:

    public ArrayList<Task> parseSaveFile(File txt) {
        try {
            txt.getAbsolutePath();
            txt.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Scanner sc = null;
        try {
            sc = new Scanner(txt);
            while (sc.hasNextLine()) {
                String text = sc.nextLine();

                String[] split = text.split(" \\| ");
                assert split.length > 0 : "Save file is empty";
                String firstChar = split[0];
                assert firstChar == "T" || firstChar == "D" || firstChar == "E" : "Save file is corrupted";

                switch (firstChar) {
                case "T":
                    String taskName = split[2];

                    Task todo = new ToDo(taskName);
                    taskList.add(todo);

                    boolean isDone = Boolean.parseBoolean(split[1]);
                    if (isDone) {
                        todo.markAsDone();
                    }
                    break;

                case "D":
                    taskName = split[2];

                    LocalDateTime date = LocalDateTime.parse(split[3]);

                    Task deadline = new Deadline(taskName, date);
                    taskList.add(deadline);

                    isDone = Boolean.parseBoolean(split[1]);
                    if (isDone) {
                        deadline.markAsDone();
                    }
                    break;

                case "E":
                    taskName = split[2];

                    String time = split[3];

                    Task event = new Event(taskName, time);
                    taskList.add(event);

                    isDone = Boolean.parseBoolean(split[1]);
                    if (isDone) {
                        event.markAsDone();
                    }
                    break;
                default:
                    break;
                }
            }
        } catch (FileNotFoundException e) {
            System.out.println(e.toString());
        }
        return taskList;
    }

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/meowmeow/Meowmeow.java lines 24-28:

    /**
     * Method that gets the response from the chatbot.
     *
     * @param input the user input.
     */

Example from src/main/java/meowmeow/events/Task.java lines 22-24:

    /**
     * Method that marks the task as done.
     */

Example from src/main/java/meowmeow/events/Task.java lines 29-31:

    /**
     * Method that marks the task as not done.
     */

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 👍

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

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