Skip to content

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

Description

@nus-se-bot

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

Example from src/main/java/Jard/Deadline.java lines 1-1:

package Jard;

Example from src/main/java/Jard/DialogBox.java lines 1-1:

package Jard;

Example from src/main/java/Jard/Event.java lines 1-1:

package Jard;

Suggestion: Follow the package naming convention specified by the coding standard.

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/Jard/Jard.java lines 49-95:

    public String getResponse(String input) {
        String[] inputParts = Parser.parseCommand(input);
        String command = inputParts[0];
        String response;

        try {
            switch (command) {
                case "bye":
                    response = ui.showBye();
                    break;
                case "list":
                    response = ui.showTaskList(tasks);
                    break;
                case "mark":
                    int markIndex = Parser.parseTaskIndex(inputParts[1], tasks.size());
                    Task markTask = tasks.get(markIndex);
                    markTask.markAsDone();
                    response = ui.showMarkTask(markTask);
                    break;
                case "unmark":
                    int unmarkIndex = Parser.parseTaskIndex(inputParts[1], tasks.size());
                    Task unmarkTask = tasks.get(unmarkIndex);
                    unmarkTask.markAsNotDone();
                    response = ui.showUnmarkTask(unmarkTask);
                    break;
                case "delete":
                    int deleteIndex = Parser.parseTaskIndex(inputParts[1], tasks.size());
                    Task deleteTask = tasks.remove(deleteIndex);
                    response = ui.showDeleteTask(deleteTask, tasks.size());
                    break;
                case "find":
                    String keyword = inputParts[1];
                    List<Task> matchingTasks = findTasks(keyword);
                    response = ui.showFindResults(matchingTasks);
                    break;
                default:
                    Task newTask = Parser.parseTask(input);
                    tasks.add(newTask);
                    response = ui.showAddTask(newTask, tasks.size());
                    break;
            }
            storage.saveTasks(tasks);
        } catch (JardException e) {
            response = ui.showError(e.getMessage());
        }
        return response;
    }

Example from src/main/java/Jard/Parser.java lines 29-73:

    public static Task parseTask(String input) throws JardException {
        String[] inputParts = input.split(" ", 2);
        String command = inputParts[0];

        if (command.equals("todo")) {
            if (inputParts.length > 1) {
                return new Todo(inputParts[1]);
            } else {
                throw new JardException("The description of a todo cannot be empty.");
            }
        } else if (command.equals("deadline")) {
            if (inputParts.length > 1) {
                String[] details = inputParts[1].split("/by", 2);
                if (details.length < 2) {
                    throw new JardException("Invalid format! Deadline should be /by.");
                }
                try {
                    LocalDateTime byDateTime = parseDateTime(details[1].trim());
                    return new Deadline(details[0].trim(), byDateTime.toString());
                } catch (Exception e) {
                    throw new JardException("Invalid date and time format for deadline! Use 'yyyy-MM-dd HHmm'.");
                }
            } else {
                throw new JardException("The description of a deadline cannot be empty.");
            }
        } else if (command.equals("event")) {
            if (inputParts.length > 1) {
                String[] details = inputParts[1].split("/from|/to");
                if (details.length != 3) {
                    throw new JardException("Invalid format! Events should be /from and /to.");
                }
                try {
                    LocalDateTime fromDateTime = parseDateTime(details[1].trim());
                    LocalDateTime toDateTime = parseDateTime(details[2].trim());
                    return new Event(details[0].trim(), fromDateTime.toString(), toDateTime.toString());
                } catch (Exception e) {
                    throw new JardException("Invalid date and time format for event! Use 'yyyy-MM-dd HHmm'.");
                }
            } else {
                throw new JardException("The description of an event cannot be empty.");
            }
        } else {
            throw new JardException("Invalid command!");
        }
    }

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/Jard/Jard.java lines 101-105:

    /**
     * The main method serves as the entry point for the application.
     *
     * @param args Command-line arguments (not used).
     */

Example from src/main/java/Jard/Ui.java lines 11-13:

    /**
     * Construct a Ui instance.
     */

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

possible problems in commit 4f244e7:


Add assert statements to document key assumptions in the code

Using Java's assert feature to document important assumptions that should hold at various points in the code helps improve code reliability.

Added assert statements like in the getJardResponse method to document the assumption that both the text and img parameters should not be null.


  • body not wrapped at 72 characters: e.g., Using Java's assert feature to document important assumptions that should hold at various points in the code helps improve code reliability.

possible problems in commit 5bd63a6:


finished level-10


  • Not in imperative mood (?)

Suggestion: Follow the given conventions for Git commit messages for future commits (do not modify past commit messages as doing so will change the commit timestamp that we used to detect your commit timings).

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