Skip to content

Sharing iP code quality feedback [for @jaredlhf] #3

@nus-se-bot

Description

@nus-se-bot

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 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/jared/task/TaskList.java lines 36-107:

    public String add(String command, String fullCommand) throws DukeException {
        Task newTask;
        String desc;
        String dateStr;
        String[] dateTime;
        LocalDate date;
        LocalTime time;

        if (command.equals("todo")) {
            try {
                desc = fullCommand.split(" ", 2)[1];
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new DukeException("OOPS!!! The description of a todo cannot be empty.");
            }
            newTask = new Todo(desc);
        } else if (command.equals("deadline")) {
            try {
                String body = fullCommand.split(" ", 2)[1];
                desc = body.split("/by", 2)[0].trim();
                dateStr = body.split("/by", 2)[1].trim();
                dateTime = dateStr.split(" ");
                String d = dateTime[0];
                date = LocalDate.parse(d);

                if (dateTime.length > 1) {
                    String t = dateTime[1];
                    time = LocalTime.parse(t);
                    newTask = new Deadline(desc, date, time);
                } else {
                    newTask = new Deadline(desc, date);
                }

            } catch (ArrayIndexOutOfBoundsException e) {
                throw new DukeException("OOPS!!! The description of a deadline cannot be empty.");
            } catch (DateTimeParseException e) {
                System.out.println(e.getMessage());
                throw new DukeException("Invalid date. Please enter the date (yyyy-mm-dd)");
            }
        } else if (command.equals("event")) {
            try {
                String body = fullCommand.split(" ", 2)[1];
                desc = body.split("/at", 2)[0].trim();
                dateStr = body.split("/at", 2)[1].trim();
                dateTime = dateStr.split(" ");
                String d = dateTime[0];
                date = LocalDate.parse(d);

                if (dateTime.length > 1) {
                    String t = dateTime[1];
                    time = LocalTime.parse(t);
                    newTask = new Event(desc, date, time);
                } else {
                    newTask = new Event(desc, date);
                }

            } catch (ArrayIndexOutOfBoundsException e) {
                throw new DukeException("OOPS!!! The description of a event cannot be empty.");
            } catch (DateTimeParseException e) {
                throw new DukeException("Invalid date and time. Please enter the date (yyyy-mm-dd)");
            }
        } else {
            throw new DukeException("OOPS!!! I'm sorry, but I don't know what that means :-(");
        }

        tasks.add(newTask);
        storage.saveData(tasks);

        return String.format("Got it. I've added this task:\n"
                        + "%s\nNow you have %d tasks in the list.",
                newTask, tasks.size()
        );
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Header Comments

Example from src/main/java/jared/Jared.java lines 45-47:

    /**
     * Main function.
     */

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 👍

ℹ️ The bot account @cs2103-bot 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.

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