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 @sohenze] #6

Open
soc-se-script opened this issue Sep 10, 2022 · 0 comments
Open

Sharing iP code quality feedback [for @sohenze] #6

soc-se-script opened this issue Sep 10, 2022 · 0 comments

Comments

@soc-se-script
Copy link

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

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/duke/Parser.java lines 28-102:

    public static Command parse(String fullCommand) throws InvalidInputException, InvalidIndexException,
            DateTimeParseException, InvalidDescriptionException, InvalidTimeException {

        fullCommand += " ";
        String command = fullCommand.substring(0, fullCommand.indexOf(' ')).trim();
        int timeIndex;
        int descIndex;
        int targetIndex;

        switch (command) {
        case "list":
            return new ListCommand();

        case "unmark":
            if (fullCommand.trim().length() <= 6) {
                throw new InvalidIndexException();
            }

            targetIndex = Integer.parseInt(fullCommand.substring(6).trim()) - 1;
            return new MarkCommand(false, targetIndex);

        case "mark":
            if (fullCommand.trim().length() <= 4) {
                throw new InvalidIndexException();
            }

            targetIndex = Integer.parseInt(fullCommand.substring(4).trim()) - 1;
            return new MarkCommand(true, targetIndex);

        case "delete":
            if (fullCommand.trim().length() <= 6) {
                throw new InvalidIndexException();
            }

            targetIndex = Integer.parseInt(fullCommand.substring(6).trim()) - 1;
            return new DeleteCommand(targetIndex);

        case "find":
            return new FindCommand(fullCommand.substring(4).trim());

        case "todo":
            return new TodoCommand(fullCommand.substring(4).trim());

        case "editd":
            if (fullCommand.trim().length() <= 5) {
                throw new InvalidIndexException();
            }

            targetIndex = Integer.parseInt(fullCommand.substring(5).trim().substring(0, 1));
            descIndex = fullCommand.indexOf("/d");
            if (descIndex == -1) {
                throw new InvalidDescriptionException();
            }
            return new EditDescCommand(targetIndex - 1, fullCommand.substring(descIndex + 2).trim());

        case "deadline":
            timeIndex = fullCommand.indexOf("/by");
            if (timeIndex == -1) {
                throw new InvalidTimeException();
            }
            return new DeadlineCommand(fullCommand.substring(8, timeIndex - 1).trim(),
                    fullCommand.substring(timeIndex + 3).trim());

        case "event":
            timeIndex = fullCommand.indexOf("/at");
            if (timeIndex == -1) {
                throw new InvalidTimeException();
            }
            return new EventCommand(fullCommand.substring(5, timeIndex - 1).trim(),
                    fullCommand.substring(timeIndex + 3).trim());

        default:
            throw new InvalidInputException();
        }
    }

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

    public ArrayList<Task> loadTaskFile() {
        File taskFile = new File(fileLocation);
        ArrayList<Task> tasks = new ArrayList<Task>();

        //Checks if storage task file exists, if not, create one
        if (!taskFile.exists()) {
            File directory = new File(taskFile.getParent());
            directory.mkdir();
        }
        try {
            taskFile.createNewFile();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }

        //Parsing data in storage task file
        try {
            Scanner sc = new Scanner(taskFile);
            while (sc.hasNext()) {
                String line = sc.nextLine();
                char taskType = line.charAt(0);
                boolean taskIsDone = line.charAt(ISDONE_MARKER) == '1';
                String taskDesc;
                String taskTime;

                switch (taskType) {
                case 'T':
                    taskDesc = line.substring(DESC_MARKER).trim();
                    if (taskDesc.isEmpty()) {
                        throw new InvalidStorageDataException();
                    }
                    tasks.add(new ToDo(taskDesc, taskIsDone));
                    break;

                case 'D':
                    taskDesc = line.substring(DESC_MARKER, line.indexOf('(')).trim();
                    taskTime = line.substring(line.indexOf('(') + 1, line.indexOf(')')).trim();
                    if (taskDesc.isEmpty() | taskTime.isEmpty()) {
                        throw new InvalidStorageDataException();
                    }
                    tasks.add(new Deadline(taskDesc, taskIsDone, taskTime));
                    break;

                case 'E':
                    taskDesc = line.substring(DESC_MARKER, line.indexOf('(')).trim();
                    taskTime = line.substring(line.indexOf('(') + 1, line.indexOf(')')).trim();
                    if (taskDesc.isEmpty() | taskTime.isEmpty()) {
                        throw new InvalidStorageDataException();
                    }
                    tasks.add(new Event(taskDesc, taskIsDone, taskTime));
                    break;

                default:
                    throw new InvalidStorageDataException();
                }
            }
            sc.close();

        } catch (FileNotFoundException | InvalidStorageDataException e) {
            Ui.appendDukeResponse(e.getMessage());
        }
        return tasks;
    }

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/Parser.java lines 25-27:

    /**
     * Parse user input and returns a command
     */

Example from src/main/java/duke/Ui.java lines 59-61:

    /**
     * Reset dukeResponse to an empty string
     */

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 👍

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