Skip to content

Sharing iP code quality feedback [for @Eclipse-Dominator] - Round 2 #10

@soc-se-bot-red

Description

@soc-se-bot-red

@Eclipse-Dominator 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/command/NoParamCommand.java lines 11-11:

    private boolean invalid;

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/test/java/duke/util/DataParserTest.java lines 53-53:

        // new ParsedData(bye, "b", "c");

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

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

    public static void main(String[] args) {
        Optional<Boolean> launchWithGui = Optional.empty();
        Optional<String> saveFile = Optional.empty();
        int i = -1;
        while (++i < args.length) {
            switch (LaunchFlagEnum.getFlag(args[i])) {
            case NO_GUI:
                if (launchWithGui.isPresent()) {
                    System.out.println(LaunchFlagErrMsg.CONFLICTING_LAUNCH);
                    return;
                }
                launchWithGui = Optional.of(false);
                break;
            case GUI:
                if (launchWithGui.isPresent()) {
                    System.out.println(LaunchFlagErrMsg.CONFLICTING_LAUNCH);
                    return;
                }
                launchWithGui = Optional.of(true);
                break;
            case SAVE_FILE:
                if (++i == args.length) {
                    System.out.println(LaunchFlagErrMsg.UNSPECIFIED_SAVE_FILE);
                    return;
                }
                saveFile = Optional.of(args[i]);
                break;
            case NULL_FLAG:
                System.out.printf(LaunchFlagErrMsg.UNRECOGNISED_FLAG.toString(), args[i]);
                return;
            case HELP:
                System.out.println(LaunchFlagEnum.getHelp());
                return;
            default:
                System.out.printf(LaunchFlagErrMsg.UNIMPLEMENTED_FLAG.toString(), args[i]);
                return;
            }
        }
        if (launchWithGui.orElse(true)) {
            Launcher.main(saveFile.map(x -> new String[] {x}).orElse(new String[] {}));
            return;
        }
        Duke duke = saveFile.map(x -> createApplication(x)).orElseGet(() -> createApplication());
        duke.run();
    }

Example from src/test/java/duke/util/DataParserTest.java lines 51-106:

    public void dataToCommandTest() {
        ParsedData dummy;
        // new ParsedData(bye, "b", "c");
        for (CommandsEnum c : CommandsEnum.values()) {
            dummy = new ParsedData(c.toString(), "b", "c");
            Command command = DataParser.dataToCommand(dummy);
            assertEquals(command instanceof Command, true);

            if (command instanceof ByeCommand && c == CommandsEnum.BYE) {
                continue;
            }
            if (command instanceof ListCommand && c == CommandsEnum.LIST) {
                continue;
            }
            if (command instanceof MarkCommand && c == CommandsEnum.MARK) {
                continue;
            }
            if (command instanceof UnmarkCommand && c == CommandsEnum.UNMARK) {
                continue;
            }
            if (command instanceof DeleteCommand && c == CommandsEnum.DELETE) {
                continue;
            }
            if (command instanceof TodoCommand && c == CommandsEnum.TODO) {
                continue;
            }
            if (command instanceof DeadlineCommand && c == CommandsEnum.DEADLINE) {
                continue;
            }
            if (command instanceof EventCommand && c == CommandsEnum.EVENT) {
                continue;
            }
            if (command instanceof ByCommand && c == CommandsEnum.BY) {
                continue;
            }
            if (command instanceof FindCommand && c == CommandsEnum.FIND) {
                continue;
            }
            if (command instanceof AliasCommand && c == CommandsEnum.ADDCOMMAND) {
                continue;
            }
            if (command instanceof DeleteAliasCommand && c == CommandsEnum.DELETECOMMAND) {
                continue;
            }
            if (command instanceof SwapFaceCommand && c == CommandsEnum.SWAP) {
                continue;
            }
            if (command instanceof ResetAliasCommand && c == CommandsEnum.RESETALIAS) {
                continue;
            }
            if (command instanceof InvalidCommand && c == CommandsEnum.INVALID) {
                continue;
            }
            fail();
        }
    }

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/duke/command/AliasCommand.java lines 20-24:

    /**
     * Create a instance of the deadline command.
     *
     * @param d ParsedData from the command input
     */

Example from src/main/java/duke/command/CommandSelector.java lines 73-77:

    /**
     * Method to get the correct enum based on string version
     *
     * @return returns the Enum for the command
     */

Example from src/main/java/duke/command/DeleteAliasCommand.java lines 18-22:

    /**
     * Create a instance of the deadline command.
     *
     * @param d ParsedData from the command input
     */

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.

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