Skip to content

Sharing iP code quality feedback [for @Xczheng0105] #1

Description

@soc-se-bot-red

@Xczheng0105 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/trackie/tasks/Task.java lines 8-8:

    protected boolean completed;

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/trackie/commands/AddCommand.java lines 49-163:

    public String execute(TaskList tasklist, Storage storage) throws TrackieException {
        try {
            switch (arguments[0]) {
            case "todo":
                if (arguments.length == 1) {
                    throw new TrackieException("Correct usage: todo [desc]");
                }
                while (ptr < arguments.length) {
                    retriever.append(arguments[ptr]).append(" ");
                    ptr++;
                }
                description = retriever.substring(0, retriever.length() - 1);

                Task todoTask = new Todo(description);
                tasklist.addTask(todoTask);
                storage.save();
                return "Added: " + todoTask.toString();
            case "deadline":
                if (arguments.length == 1) {
                    throw new TrackieException("Correct usage: deadline [desc] /by [yyyy-mm-dd]");
                }

                //retrieve the description
                while (!arguments[ptr].equals("/by")) {
                    if (ptr == arguments.length - 1) {
                        throw new TrackieException("Correct usage: deadline [desc] /by [yyyy-mm-dd]");
                    }
                    retriever.append(arguments[ptr]).append(' ');
                    ptr++;
                }
                if (retriever.isEmpty()) {
                    throw new TrackieException("Description cannot be empty!");
                } else {
                    description = retriever.substring(0, retriever.length() - 1);
                }
                retriever.setLength(0); //clear the stringbuilder

                //retrieve the deadline
                ptr++;
                while (ptr < arguments.length) {
                    retriever.append(arguments[ptr]).append(' ');
                    ptr++;
                }

                if (retriever.isEmpty()) {
                    throw new TrackieException("Deadline cannot be empty!");
                } else {
                    deadline = retriever.substring(0, retriever.length() - 1);
                }

                Task deadlineTask = new Deadline(description, deadline);
                tasklist.addTask(deadlineTask);
                storage.save();
                return "Added: " + deadlineTask.toString();

            case "event":
                if (arguments.length == 1) {
                    throw new TrackieException("Correct usage: event [desc] /from [start] /to [end]");
                }

                //retrieve the description
                while (!arguments[ptr].equals("/from")) {
                    if (ptr == arguments.length - 1) {
                        throw new TrackieException("Correct usage: event [desc] /from [start] /to [end]");
                    }
                    retriever.append(arguments[ptr]).append(' ');
                    ptr++;
                }
                if (retriever.isEmpty()) {
                    throw new TrackieException("Description cannot be empty!");
                } else {
                    description = retriever.substring(0, retriever.length() - 1);
                }
                retriever.setLength(0); //clear the stringbuilder;

                ptr++;
                if (ptr >= arguments.length) {
                    throw new TrackieException("Correct usage: event [desc] /from [start] /to [end]");
                }
                //retrieve the start time
                while (!arguments[ptr].equals("/to")) {
                    if (ptr == arguments.length - 1) {
                        throw new TrackieException("Correct usage: event [desc] /from [start] /to [end]");
                    }
                    retriever.append(arguments[ptr]).append(" ");
                    ptr++;
                }
                if (retriever.isEmpty()) {
                    throw new TrackieException("Start timing cannot be empty!");
                } else {
                    start = retriever.substring(0, retriever.length() - 1);
                }
                retriever.setLength(0); //clear the retriever
                ptr++;
                //retrieve the end time
                while (ptr < arguments.length) {
                    retriever.append(arguments[ptr]).append(" ");
                    ptr++;
                }
                if (retriever.isEmpty()) {
                    throw new TrackieException("End timing cannot be empty!");
                } else {
                    end = retriever.substring(0, retriever.length() - 1);
                }
                Task eventTask = new Event(description, start, end);
                tasklist.addTask(eventTask);
                storage.save();
                return "Added: " + eventTask.toString();
            default:
                return "Invalid Command bro";
            }
        } catch (TrackieException | DateTimeParseException e) {
            return e.getMessage();
        }
    }

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 👍


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