Giter VIP home page Giter VIP logo

cs2103t-ip's People

Contributors

damithc avatar eclipse-dominator avatar j-lum avatar jiachen247 avatar seanleong339 avatar wxwern avatar

cs2103t-ip's Issues

Sharing iP code quality feedback [for @wxwern]

@wxwern 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/todoify/taskmanager/task/Task.java lines 33-33:

    private boolean completed = false;

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

No easy-to-detect issues ๐Ÿ‘

Aspect: Method Length

Example from src/main/java/todoify/chatbot/Chatbot.java lines 205-264:

    private void processCommand(ChatCommand chatCommand) {
        try {
            switch (chatCommand.getOperation()) {
            case MARK_COMPLETE:
            case UNMARK_COMPLETE:
            case DELETE:
                this.processCommandAssertNumericData(chatCommand);
                break;

            case ADD_TODO:
            case ADD_DEADLINE:
            case ADD_EVENT:
            case SEARCH:
                this.processCommandAssertHasData(chatCommand);
                break;

            case LIST:
            case HELP:
            case EXIT:
                this.processCommandAssertNoData(chatCommand);
                break;

            case UNKNOWN:
            default:
                throw new ChatbotCommandException("Sorry, idgi :(");
            }
        } catch (ChatbotIrrelevantOperationException e) {
            // This will only be thrown if the code path unexpectedly processes data in a format not relevant to the
            // operation in question. In other words, entering this code block is likely a programmer error.
            assert false;
            this.sendMessage(ChatMessage.SenderType.CHATBOT, "Oops! There was an internal error.");

        } catch (ChatbotCommandException e) {
            // All other errors related to command processing will be caught here, and should be shown to the user.
            this.sendMessage(ChatMessage.SenderType.CHATBOT, "Oops! " + e.getLocalizedMessage());

        } catch (Exception e) {
            // Any other exceptions are errors unrelated to the command itself. In this case, let the user know anyway.
            e.printStackTrace();
            this.sendMessage(ChatMessage.SenderType.CHATBOT, String.format(
                    "Oh no, something's wrong! [%s] %s",
                    e.getClass().getSimpleName(),
                    e.getLocalizedMessage()
            ));
        }

        try {
            this.taskManager.saveToStorage();
        } catch (IOException e) {
            this.sendMessage(
                    ChatMessage.SenderType.CHATBOT,
                    "Oops! I'm having problems saving your data to storage. Your data may not be preserved."
                            + String.format(
                            "The error was: [%s] %s",
                            e.getClass().getSimpleName(),
                            e.getLocalizedMessage()
                    )
            );
        }
    }

Example from src/main/java/todoify/chatbot/Chatbot.java lines 272-350:

    private void processCommandAssertNumericData(ChatCommand chatCommand) throws ChatbotCommandException {
        switch (chatCommand.getOperation()) {
        case MARK_COMPLETE:
        case UNMARK_COMPLETE:
        case DELETE:
            break;
        default:
            throw new ChatbotIrrelevantOperationException(String.format(
                    "The command '%s' should not have numeric data only, "
                            + "but the internal code attempted to assert that it does",
                    chatCommand.getName()
            ));
        }

        int index;
        Task task;

        // Process the input
        try {
            index = Integer.parseInt(chatCommand.getData()) - 1;
        } catch (NumberFormatException | NullPointerException e) {
            throw new ChatbotInvalidCommandFormatException((String.format(
                    "The command '%s' must be followed by a number representing the task number!",
                    chatCommand.getName()
            )));
        }

        try {
            task = this.taskManager.getTask(index);
        } catch (IndexOutOfBoundsException e) {
            throw new ChatbotInvalidCommandFormatException(String.format(
                    "There is no task in the list numbered %d!",
                    index + 1
            ));
        }

        assert index >= 0 && index < this.taskManager.getTaskCount();
        assert task != null;

        // Let's see what we should do!
        if (chatCommand.getOperation() == ChatCommand.Operation.DELETE) {

            // Delete the task accordingly. We already checked the index so it should be correct.
            this.taskManager.removeTask(index);

            // Send an appropriate reply.
            this.sendMessage(ChatMessage.SenderType.CHATBOT, String.format(
                    "Alright, I've deleted this task:\n   %s\nYou're left with %d tasks now! :)",
                    task,
                    this.taskManager.getTaskCount()
            ));

        } else {

            // Mark the task as done or not accordingly
            boolean completed = chatCommand.getOperation() == ChatCommand.Operation.MARK_COMPLETE;
            if (task.isCompleted() == completed) {
                throw new ChatbotCommandException(completed
                        ? "The task was already done!"
                        : "The task was already not done!");
            }
            task.setCompleted(completed);

            // Send an appropriate reply
            if (completed) {
                this.sendMessage(
                        ChatMessage.SenderType.CHATBOT,
                        String.format("Nice! I've marked this task as done:\n   %s", task)
                );
            } else {
                this.sendMessage(
                        ChatMessage.SenderType.CHATBOT,
                        String.format("OK, I've marked this task as not done yet:\n   %s", task)
                );
            }

        }

    }

Example from src/main/java/todoify/chatbot/Chatbot.java lines 358-439:

    private void processCommandAssertNoData(ChatCommand chatCommand) throws ChatbotCommandException {
        switch (chatCommand.getOperation()) {
        case LIST:
        case HELP:
        case EXIT:
            break;
        default:
            throw new ChatbotIrrelevantOperationException(String.format(
                    "The command '%s' should have included data, "
                            + "but the internal code attempted to assert that it does not.",
                    chatCommand.getName()
            ));
        }

        if (!chatCommand.getData().isBlank() || chatCommand.hasParams()) {
            throw new ChatbotInvalidCommandFormatException(String.format(
                    "Hmm, the command '%s' should not have anything following it. Is that a typo?",
                    chatCommand.getName()
            ));
        }

        StringBuilder builder;
        switch (chatCommand.getOperation()) {
        case LIST:
            builder = new StringBuilder();

            if (this.taskManager.getTaskCount() > 0) {
                builder.append("Here are your tasks, glhf! :)");
            } else {
                builder.append("Oh nice! You have no tasks! :>");
            }

            this.taskManager.getTaskIndexedStream()
                    .forEach(integerTaskPair -> {
                        builder.append("\n");
                        builder.append(integerTaskPair.getKey() + 1);
                        builder.append(". ");
                        builder.append(integerTaskPair.getValue().toString());
                    });

            this.sendMessage(ChatMessage.SenderType.CHATBOT, builder.toString());
            break;

        case HELP:
            builder = new StringBuilder();
            builder.append("No problem. Here's a summary of all possible command names and their functions!\n\n");

            for (ChatCommand.Operation op : ChatCommand.Operation.values()) {

                var aliases = op.getSupportedNameAliases();
                var quotedAliases = Arrays.stream(aliases)
                        .map(s -> '"' + s + '"')
                        .collect(Collectors.toList());

                if (quotedAliases.size() == 0) {
                    continue;
                }

                String commandTitle = String.join(", ", quotedAliases);
                String commandDescription = op.getDescription();
                String commandSyntax = String.format(op.getSyntaxDescriptionAsFormatString(), aliases[0]);

                builder.append(String.format("    %s\n", commandTitle));
                builder.append(String.format("        %s\n", commandDescription));
                builder.append(String.format("        Format: \"%s\"\n", commandSyntax));
                builder.append('\n');
            }

            builder.append("Commands listed with multiple names above are synonyms and can be used interchangeably.\n");
            builder.append("Hope this helps! :)");

            this.sendMessage(ChatMessage.SenderType.CHATBOT, builder.toString());
            break;

        case EXIT:
            this.closeConversation();
            break;

        default:
            break;
        }
    }

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

Suggestion: Consider breaking large classes into smaller ones, if appropriate. A long class is a sign that perhaps it is dong 'too much'.

Aspect: Header Comments

Example from src/main/java/todoify/chatbot/Chatbot.java lines 151-157:

    /**
     * Method to send a message to the chatbot from the user.
     *
     * @param message The message string to send.
     * @return The resulting message sent.
     * @throws ChatbotRuntimeException if the conversation is closed.
     */

Example from src/main/java/todoify/chatbot/Chatbot.java lines 167-172:

    /**
     * Internal method to send a message.
     *
     * @param message The message to send.
     * @return The resulting message sent.
     */

Example from src/main/java/todoify/chatbot/Chatbot.java lines 180-184:

    /**
     * Internal method to process newly received messages.
     *
     * @param message The message to process.
     */

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 [email protected] if you want to follow up on this post.

Sharing iP code quality feedback [for @wxwern] - Round 2

@wxwern We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

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

No easy-to-detect issues ๐Ÿ‘

Aspect: Class size

Suggestion: Consider breaking large classes into smaller ones, if appropriate. A long class is a sign that perhaps it is dong 'too much'.

Aspect: Header Comments

Example from src/main/java/todoify/taskmanager/task/Task.java lines 56-60:

    /**
     * Whether the task is marked as completed.
     *
     * @return true if completed, false otherwise.
     */

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 ๐Ÿ‘


โ— You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality 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 [email protected] if you want to follow up on this post.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.