Skip to content

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

@soc-se-bot-blue

Description

@soc-se-bot-blue

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

Example from src/main/java/Nebula.java lines 62-63:

            else {

Suggestion: As specified by the coding standard, use egyptian style braces.

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/Nebula.java lines 10-114:

    public static void main(String[] args) {
        Ui ui = new Ui();
        TaskList taskList = new TaskList();
        Parser parser = new Parser();

        System.out.println(ui.greeting());

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            String command = sc.nextLine();

            if(command.equals("bye")) {
                System.out.println(ui.goodbye());
                break;
            }

            else if(command.equals("list")) {
                System.out.println(ui.displayList());
            }

            else if(command.startsWith("mark")) {
                try {
                    validateCommand(command, taskList);
                } catch (NebulaException e) {
                    System.out.println(e.getMessage());
                    continue;
                }
                int taskNum = parser.splitCommandAndTaskNumber(command);
                System.out.println(taskList.markTask(taskNum));
            }

            else if(command.startsWith("unmark")) {
                try {
                    validateCommand(command, taskList);
                } catch (NebulaException e) {
                    System.out.println(e.getMessage());
                    continue;
                }
                int taskNum = parser.splitCommandAndTaskNumber(command);
                System.out.println(taskList.unmarkTask(taskNum));
            }

            else if(command.startsWith("delete")) {
                try {
                    validateCommand(command, taskList);
                } catch (NebulaException e) {
                    System.out.println(e.getMessage());
                    continue;
                }
                int taskNum = parser.splitCommandAndTaskNumber(command);
                System.out.println(taskList.deleteTask(taskNum));
            }

            else {
                try {
                    validateCommand(command, taskList);
                } catch (NebulaException e) {
                    System.out.println(e.getMessage());
                    continue;
                }

                TaskType taskType = parseTaskType(command);

                switch (taskType) {
                    case TODO:
                        String taskDescription = parser.splitCommandAndTaskDescription(command);
                        Task newTodo = new Todo(taskDescription);
                        String addedTodo = taskList.addTask(newTodo);
                        System.out.println(addedTodo);
                        break;

                    case DEADLINE:
                        String taskInformation = parser.splitCommandAndTaskDescription(command);
                        String taskDescriptionDeadline = parser.splitDeadlineCommand(taskInformation)[0];
                        String taskDeadline = parser.splitDeadlineCommand(taskInformation)[1];
                        Task newDeadline = new Deadline(taskDescriptionDeadline, taskDeadline);
                        String addedDeadline = taskList.addTask(newDeadline);
                        System.out.println(addedDeadline);
                        break;

                    case EVENT:
                        String taskInfo = parser.splitCommandAndTaskDescription(command);
                        String taskDescriptionEvent = parser.splitEventCommand(taskInfo)[0];
                        String startInfo = parser.splitEventCommand(taskInfo)[1];
                        String endInfo = parser.splitEventCommand(taskInfo)[2];

                        String taskStart = parser.splitCommandAndTaskDescription(startInfo);
                        String taskEnd = parser.splitCommandAndTaskDescription(endInfo);

                        Task newEvent = new Event(taskDescriptionEvent, taskStart, taskEnd);
                        String addedEvent = taskList.addTask(newEvent);
                        System.out.println(addedEvent);
                        break;

                    case UNKNOWN:
                        System.out.println("Unknown command type.");
                        break;
                }

            }

        }


    }

Example from src/main/java/Nebula.java lines 123-165:

    public static void validateCommand(String command, TaskList taskList) throws NebulaException {
        Parser parser = new Parser();
        Ui ui = new Ui();

        if (command.isEmpty()) {
            throw new NebulaException("Please enter a command!");
        } else if (!(command.startsWith("todo") || command.startsWith("deadline")
                || command.startsWith("event") || command.startsWith("mark")
                || command.startsWith("unmark") || command.startsWith("delete")
                || command.startsWith("list") || command.startsWith("bye"))) {
            throw new NebulaException(ui.displayUnknownCommandException());
        } else if (command.startsWith("mark") || command.startsWith("unmark") || command.startsWith("delete")) {
            String[] parts = command.split(" ", 2);
            if (parts.length < 2 || parts[1].trim().isEmpty()) {
                throw new NebulaException(ui.displayUnknownTaskNumberException());
            }
            try {
                int taskIndex = Integer.parseInt(parts[1].trim()) - 1; // Convert to 0-based index
                if (taskIndex < 0 || taskIndex >= TaskList.getTaskListLength()) {
                    throw new NebulaException(ui.displayNonexistentTaskNumberException());
                }
            } catch (NumberFormatException e) {
                throw new NebulaException(ui.displayUnknownTaskNumberException());
            }
        } else {
            String[] parts = command.split(" ", 2);
            if (parts.length < 2 || parts[1].trim().isEmpty()) {
                throw new NebulaException(ui.displayUnknownMessageException());
            }

            String description = parts[1].trim();

            if (command.startsWith("deadline")) {
                if (!description.contains("/by")) {
                    throw new NebulaException(ui.displayUnknownDeadlineException());
                }
            } else if (command.startsWith("event")) {
                if (!description.contains("/from") || !description.contains("/to")) {
                    throw new NebulaException(ui.displayUnknownEventTimingException());
                }
            }
        }
    }

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/Nebula.java lines 4-9:

    /**
     * Entry point of the application. Initializes the UI, task list, and parser,
     * then processes user commands in a loop until "bye" is entered
     *
     * @param args command-line arguments (not used)
     */

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

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