Skip to content

Sharing iP code quality feedback [for @jianyangg] #5

@soc-se-bot-red

Description

@soc-se-bot-red

@jianyangg 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/Task.java lines 9-9:

    private boolean prioritySet;

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

        // this.taskList.addAll(savedTaskList);

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

        // System.out.println("\nWelcome to Chatty.\n" + LOGO);

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

    // private String sendGreeting() {

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

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

    private String handleTextInput(String inputString) {
        assert inputString != null : "Input string cannot be null";
        assert !inputString.isEmpty() : "Input string cannot be empty";
        // handle key logic here.
        String command = inputString.split(" ")[0];
        int taskIndex;

        switch (command) {
        case "bye":
            return ui.sendFarewell();

        case "list":
            return ui.printTaskList(tasks.toString());

        case "mark":
            // taskIndex is the second word in the input string
            taskIndex = Integer.parseInt(inputString.split(" ")[1]) - 1;

            tasks.markTaskAsDone(taskIndex);

            return ui.markTaskAsDoneMessage(tasks.taskToString(taskIndex));

        case "unmark":
            taskIndex = Integer.parseInt(inputString.split(" ")[1]) - 1;
            tasks.unmarkTaskAsDone(taskIndex);
            return ui.unmarkTaskAsDoneMessage(tasks.taskToString(taskIndex));

        case "todo":
            try {
                String taskName = inputString.substring(5);
                Task newTask = new ToDo(taskName);
                tasks.addToTaskList(newTask);
                assert !tasks.isEmpty() : "Task list should not be empty";

                return ui.addTaskOutputText(newTask, tasks.size());
            } catch (StringIndexOutOfBoundsException e) {
                return ui.showErrorMessage("\t☹ OOPS!!! The description of a todo cannot be empty.");
            }
        case "deadline":
            try {
                // stop before /by
                String taskName = inputString.substring(9, inputString.indexOf("/by") - 1);
                // get day
                String deadline = inputString.substring(inputString.indexOf("/by") + 4);
                try {
                    Task newTask = new Deadline(taskName, deadline);

                    tasks.addToTaskList(newTask);

                    return ui.addTaskOutputText(newTask, tasks.size());
                } catch (java.time.format.DateTimeParseException e) {
                    return ui.showErrorMessage("\tInvalid date format. Please use yyyy-mm-dd.");
                }
            } catch (StringIndexOutOfBoundsException e) {
                return ui.showErrorMessage("\t☹ OOPS!!! The description of a deadline cannot be empty.");
            }
        case "event":
            try {
                String taskName = inputString.substring(6, inputString.indexOf("/from") - 1);
                String from = inputString.substring(inputString.indexOf("/from") + 6, inputString.indexOf("/to") - 1);
                String to = inputString.substring(inputString.indexOf("/to") + 4);
                Task newTask = new Event(taskName, from, to);

                tasks.addToTaskList(newTask);

                return ui.addTaskOutputText(newTask, tasks.size());
            } catch (StringIndexOutOfBoundsException e) {
                return ui.showErrorMessage("\t☹ OOPS!!! The description of an event cannot be empty.");
            }
        case "delete":
            taskIndex = Integer.parseInt(inputString.split(" ")[1]) - 1;
            String msg = ui.printDeleteMessage(tasks.taskToString(taskIndex), taskIndex, tasks.size());
            tasks.deleteTask(taskIndex);
            return msg;
            
        case "find":
            String keyword = inputString.substring(5);
            String outputString = "";
            for (int i = 0; i < tasks.size(); i++) {
                if (tasks.taskToString(i).contains(keyword)) {
                    outputString += tasks.taskToString(i) + "\n";
                }
            }
            return ui.printTaskList(outputString);

        case "priority":
            // the format will be priority <index> <priority>
            // priority is an integer
            // index is an integer
            // priority is between 1 and 5
            // index is between 1 and taskList.size()
            String[] inputArr = inputString.split(" ");
            int priority = Integer.parseInt(inputArr[2]);
            taskIndex = Integer.parseInt(inputArr[1]) - 1;
            tasks.setPriority(taskIndex, priority);
            return ui.printPriorityMessage(tasks.taskToString(taskIndex), priority);

        default:
            return ui.showErrorMessage(
                    "\t☹ OOPS!!! I'm sorry, but I don't know what that means. Try again using either mark <index>,"
                            + "unmark <index>, todo <task>, deadline <task /by ..>, event <task /from .. /to ..>, or bye.");
        }

    }

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

possible problems in commit 746fb28:


Add C-Priority extension to Duke

Priority is represented using exclamation marks, printed after the task name. It ranges from 0 - 5, which in turn represents the number of exclamation mark, with 0 being the least and 5 being the highest priority


  • body not wrapped at 72 characters: e.g., Priority is represented using exclamation marks, printed after the task name. It ranges from 0 - 5, which in turn represents the number of exclamation mark, with 0 being the least and 5 being the highest priority

possible problems in commit 351d80f:


Add assertions where appropriate to validate function arguments

The addition of these assertions should help us validate our assumptions,

thus making it easier for errors and bugs to be detected.

As there are not much logic involved in this project, focus is mainly placed

on validating the input to the functions


  • body not wrapped at 72 characters: e.g., The addition of these assertions should help us validate our assumptions,

possible problems in commit 6e89ab7:


Improve the code quality in accordance with the CS2103T textbook

Code quality were improved with respect to areas such as comments,

line spacing to separate groups of related statements,

and avoided complicated expressions by breaking them down into simpler logic blocks


  • body not wrapped at 72 characters: e.g., and avoided complicated expressions by breaking them down into simpler logic blocks

Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).

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