Skip to content

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

@soc-se-script

Description

@soc-se-script

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

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/galath/parser/Parser.java lines 44-87:

    public static Command parse(String fullCommand) throws GalathException {
        String trimmedCommand = fullCommand.trim();

        // Normalize command by expanding aliases
        String normalizedCommand = expandAlias(trimmedCommand);

        if (normalizedCommand.equals("bye") || normalizedCommand.equals("exit")) {
            return new ExitCommand();
        } else if (normalizedCommand.equals("list")) {
            return new ListCommand();
        } else if (normalizedCommand.startsWith("mark ")) {
            return parseMarkCommand(normalizedCommand);
        } else if (normalizedCommand.equals("mark")) {
            throw new GalathException("Please specify which task to mark.\n     Example: mark 2 or m 2");
        } else if (normalizedCommand.startsWith("unmark ")) {
            return parseUnmarkCommand(normalizedCommand);
        } else if (normalizedCommand.equals("unmark")) {
            throw new GalathException("Please specify which task to unmark.\n     Example: unmark 2 or u 2");
        } else if (normalizedCommand.startsWith("delete ")) {
            return parseDeleteCommand(normalizedCommand);
        } else if (normalizedCommand.equals("delete")) {
            throw new GalathException("Please specify which task to delete.\n     Example: delete 3 or del 3");
        } else if (normalizedCommand.startsWith("todo ")) {
            return parseTodoCommand(normalizedCommand);
        } else if (normalizedCommand.equals("todo")) {
            throw new GalathException("The description of a todo cannot be empty.\n     Example: todo borrow book or t borrow book");
        } else if (normalizedCommand.startsWith("deadline ")) {
            return parseDeadlineCommand(normalizedCommand);
        } else if (normalizedCommand.equals("deadline")) {
            throw new GalathException("The description of a deadline cannot be empty.\n     Example: deadline return book /by 2019-12-02 or d return book /by 2019-12-02");
        } else if (normalizedCommand.startsWith("event ")) {
            return parseEventCommand(normalizedCommand);
        } else if (normalizedCommand.equals("event")) {
            throw new GalathException("The description of an event cannot be empty.\n     Example: event project meeting /from 2019-12-02 1400 /to 2019-12-02 1600 or e project meeting /from 2019-12-02 1400 /to 2019-12-02 1600");
        } else if (normalizedCommand.startsWith("on ")) {
            return parseOnCommand(normalizedCommand);
        } else if (normalizedCommand.startsWith("find ")) {
            return parseFindCommand(normalizedCommand);
        } else if (normalizedCommand.equals("find")) {
            throw new GalathException("Please specify a keyword to search for.\n     Example: find book or f book");
        } else {
            throw new GalathException("I'm sorry, but I don't know what that means :-(");
        }
    }

Example from src/main/java/galath/gui/MainWindow.java lines 72-122:

    private void handleUserInput() {
        String input = userInput.getText().trim();
        if (input.isEmpty()) {
            return;
        }

        // Show user input
        dialogContainer.getChildren().add(
                DialogBox.getUserDialog(input, userImage)
        );

        // Get response from Galath
        String response = getResponse(input);

        // Determine response type
        boolean isError = response.startsWith("OOPS!!!");
        boolean isSuccess = response.contains("Got it. I've added")
                || response.contains("Nice! I've marked")
                || response.contains("Noted. I've removed")
                || response.contains("OK, I've marked");
        boolean isExit = input.equals("bye");

        // Show Galath's response
        if (isError) {
            dialogContainer.getChildren().add(
                    DialogBox.getErrorDialog(response, galathImage)
            );
        } else if (isSuccess) {
            dialogContainer.getChildren().add(
                    DialogBox.getSuccessDialog(response, galathImage)
            );
        } else {
            dialogContainer.getChildren().add(
                    DialogBox.getGalathDialog(response, galathImage)
            );
        }

        userInput.clear();

        // Exit after showing goodbye message
        if (isExit) {
            Platform.runLater(() -> {
                try {
                    Thread.sleep(1500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Platform.exit();
            });
        }
    }

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 Messages

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