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 @Acerizm] #2

Open
soc-se-bot opened this issue Feb 11, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @Acerizm] #2

soc-se-bot opened this issue Feb 11, 2023 · 0 comments

Comments

@soc-se-bot
Copy link

@Acerizm We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.

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/Command.java lines 19-19:

    protected boolean exitStatus;

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/Duke.java lines 77-77:

            //return "Duke heard: " + input;

Example from src/main/java/duke/action/Deadline.java lines 55-55:

        //return "[D]" + super.getDescription() + " (by: " + this.day + ")";

Example from src/main/java/duke/command/DeleteCommand.java lines 33-33:

        //System.out.println("Noted! I've removed this task:");

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/exception/DukeException.java lines 21-139:

    public DukeException(TypeOfTask task, int errorCode) {
        super();
        this.errorCode = errorCode;
        this.errorTask = task;
        switch(task) {
        case todo: {
            switch(errorCode) {
            case 0:
                this.message = String.format("Oops! The description of %s cannot be empty", task.toString());
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case deadline: {
            switch(errorCode) {
            case 0:
                this.message = String.format("Oops! The description of %s cannot be empty", task.toString());
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case event: {
            switch(errorCode) {
            case 0:
                this.message = String.format("Oops! The description of %s cannot be empty", task.toString());
                break;
            case 1:
                this.message = "Please check your inputs again for the days and time given";
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case list: {
            break;
        }
        case mark: {
            switch(errorCode) {
            case 0:
                this.message = String.format("Oops! The description of %s cannot be empty", task.toString());
                break;
            case 1:
                this.message = "Please check if your inputs are valid.";
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case unmark: {
            switch(errorCode) {
            case 0:
                this.message = String.format("Oops! The description of %s cannot be empty", task.toString());
                break;
            case 1:
                this.message = "Please check if your inputs are valid.";
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case delete: {
            switch(errorCode) {
            case 0:
                this.message = String.format("Oops! The description of %s cannot be empty", task.toString());
                break;
            case 1:
                this.message = "You entered wrongly. Please try again!";
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case parser: {
            switch(errorCode) {
            case 0:
                this.message = "format of date given is not recognized";
                break;
            case 1:
                this.message = "format of time given is not recognized";
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        case storage: {
            switch(errorCode) {
            case 0:
                this.message = "Unable to retrieve data from file given. Please check if the file path is correct";
                break;
            case 1:
                this.message = "Unable to save data to disk. Something went wrong";
                break;
            default:
                this.message = "Something went wrong here";
                break;
            }
            break;
        }
        default:
            this.message = "Oops! I don't understand what it means!";
            break;
        }
    }

Example from src/main/java/duke/parser/Parser.java lines 45-145:

    public String convertToUserInput(String[] input, TypeOfTask action, String limiter) throws DukeException {
        switch(action) {
        case find: {
            String userInput = String.join(" ", Arrays.copyOfRange(input, 0, input.length));
            if (userInput.equals("") || userInput == null) {
                throw new DukeException(TypeOfTask.find, 0);
            } else {
                return userInput;
            }
        }
        case todo: {
            // changed the way the string is outputted from the array
            String userInput = String.join(" ", Arrays.copyOfRange(input, 0, input.length));
            if (userInput.equals("") || userInput == null) {
                throw new DukeException(TypeOfTask.todo, 0);
            } else {
                return userInput;
            }
        }
        case deadline: { // added braces to scope the variables below locally to each case
            // algo to detect deadline's input content
            String userInput = "";
            if (!limiter.equals("/by")) {
                for (int i = 0; i < input.length; i++) {
                    if (input[i].equals("/by")) {
                        break;
                    } else {
                        userInput += input[i] + " ";
                    }
                }
            } else {
                // to get the date and time after "/by"
                for (int i = 0; i < input.length; i++) {
                    if (input[i].equals("/by")) {
                        for (int j = i + 1; j < input.length; j++) {
                            userInput += input[j] + " ";
                        }
                        break;
                    }
                }
            }
            if (userInput.equals("") || userInput == null) {
                throw new DukeException(TypeOfTask.deadline, 0);
            } else {
                return userInput;
            }

        }
        case event: {
            String userInput = "";
            if (limiter.equals("/from")) {
                for (int i = 0; i < input.length; i++) {
                    if (input[i].equals("/from")) {
                        for (int j = i + 1; j < input.length; j++) {
                            if (input[j].equals("/to")) {
                                break;
                            } else {
                                userInput += input[j] + " ";
                            }
                        }
                        break;
                    }
                }
            } else if (limiter.equals("/to")) {
                for (int i = 0; i < input.length; i++) {
                    if (input[i].equals("/to")) {
                        for (int j = i + 1; j < input.length; j++) {
                            userInput += input[j] + " ";
                        }
                        break;
                    }
                }
            } else {
                // to get the user's input before the "/from" limiter
                for (int i = 0; i < input.length; i++) {
                    if (input[i].equals("/from")) {
                        break;
                    } else {
                        userInput += input[i] + " ";
                    }
                }
            }
            if (userInput.equals("") || userInput == null) {
                throw new DukeException(TypeOfTask.event, 0);
            } else {
                return userInput;
            }
        }
        case delete: {
            if (input.length == 0) {
                throw new DukeException(TypeOfTask.delete, 0);
            } else if (input.length > 1) {
                throw new DukeException(TypeOfTask.delete, 1);
            } else {
                return input[0];
            }
        }
        default:
            throw new DukeException();
        }
    }

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/Duke.java lines 63-67:

    /**
     * duke.Main method for Duke class
     * @param args
     * @throws Exception when unforseen error occurs.
     */

Example from src/main/java/duke/Duke.java lines 71-74:

    /**
     * You should have your own function to generate a response to user input.
     * Replace this stub with your completed method.
     */

Example from src/main/java/duke/command/Command.java lines 48-54:

    /**
     * Abstract method that allows commands to process the inputs from the user
     * @param taskList List of tasks
     * @param ui Ui object
     * @param storage Storage object
     * @throws DukeException When execute() fails due to errors during run time
     */

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

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

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