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 @Nigeltzy] - Round 2 #3

Open
soc-se-bot-red opened this issue Oct 15, 2024 · 0 comments
Open

Comments

@soc-se-bot-red
Copy link

@Nigeltzy 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/shnoop/command/MarkCommand.java lines 16-16:

    private boolean mode;

Example from src/main/java/shnoop/ui/Parser.java lines 152-152:

                                            int idx, String input, String[] commandParts, boolean ... b) {

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

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/shnoop/ui/Parser.java lines 185-274:

    public static Command parse(String input) throws ShnoopException {
        String improperInput =
                "You could travel the world, but nothing comes close to choosing a task type.\n\n"
                        + "I have a few California Gorls for you to try out. \n\n "
                        + "Try typing 'todo', 'event' or 'deadline' followed by stating the task description. \n"
                        + "Other commands you could try out too are list, mark, unmark, find, delete \n"
                        + "And don't tell anyone else I told you this but you can also type 'list 1' to sort tasks!\n"
                        + "But perhaps the most imporant of all, you MUST say 'bye' to me before leaving!"
                        + " Or else Imma forget all about your sorry donkey!";
        String[] commandParts = input.split(" ");
        int length = input.length();


        if (!contains((commandParts[0].toUpperCase()))) {
            throw new ShnoopException(improperInput);
        }
        Commands command = Commands.valueOf(commandParts[0].toUpperCase());

        switch (command) {
        case LIST:
            if (commandParts.length >= 2) {
                try {
                    return new ListCommand(Integer.parseInt(commandParts[1]));
                } catch (NumberFormatException e) {
                    throw new ShnoopException(improperInput);
                }
            }
            if (commandParts[0].toLowerCase().equals("list")
                    || commandParts[0].toLowerCase().equals("list ")
                    || (length >= 5 && isEmptyFromIdx(5, input))
                    || (commandParts.length >= 2 && commandParts[1].isEmpty())) {
                return new ListCommand();
            }
        case TODO:
            try {
                if (!startsWithTodo(input, length) || isEmptyFromIdx(5, input)
                        || commandParts[1].isEmpty()) {
                    throw new ShnoopException(improperInput);
                }
                return new AddCommand(input, Commands.TODO);
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new ShnoopException(improperInput);
            }

        case DEADLINE:
            try {
                if (!startsWithDeadline(input, length) || isEmptyFromIdx(9, input)
                        || commandParts[1].isEmpty()) {
                    throw new ShnoopException(improperInput);
                }
                return new AddCommand(input, Commands.DEADLINE);
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new ShnoopException(improperInput);
            }
        case EVENT:
            try {
                if (!startsWithEvent(input, length) || isEmptyFromIdx(6, input)
                        || commandParts[1].isEmpty()) {
                    throw new ShnoopException(improperInput);
                }
                return new AddCommand(input, Commands.EVENT);
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new ShnoopException(improperInput);
            }
        case FIND:
            if (isInvalidCommand(length, 6, 5, input, commandParts)) {
                throw new ShnoopException(improperInput);
            }
            return new FindCommand(input);
        case DELETE:
            if (isInvalidCommand(length,8, 7, input, commandParts, true)) {
                throw new ShnoopException(improperInput);
            }
            return new DeleteCommand(input);
        case MARK:
            if (isInvalidCommand(length, 6, 5, input, commandParts, true)) {
                throw new ShnoopException(improperInput);
            }
            return new MarkCommand(input, true);
        case UNMARK:
            if (isInvalidCommand(length, 8, 7, input, commandParts, true)) {
                throw new ShnoopException(improperInput);
            }
            return new MarkCommand(input, false);
        case BYE:
            return new ExitCommand();
        default:
            throw new ShnoopException(improperInput);
        }
    }

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

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