Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing iP code quality feedback [for @blackpanther9229] - Round 2 #5

Open
nus-se-script opened this issue Oct 15, 2024 · 0 comments
Open

Comments

@nus-se-script
Copy link

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

Example from src/main/java/nah/parser/Parser.java lines 25-178:

    public static Command parse(String fullCommand) throws NahException {
        assert fullCommand != null : "fullCommand cannot be null";
        String[] cmd = fullCommand.split(" ", 2);
        assert cmd[0] != null : "unexpected null value for command";

        switch (cmd[0].toLowerCase()) {
        case "bye": {
            return new Command.ExitCommand();
        }
        case "nah": {
            if (cmd.length < 2) {
                return new Command.ReactCommand("nah");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) { // the second word is not a number
                return new Command.UnknownCommand();
            }
            return new Command.NahCommand(i);
        }
        case "hi": case "hello": case "oke": case "yo": {
            return new Command.ReactCommand(cmd[0].toLowerCase());
        }
        case "clean": {
            if (cmd.length >= 2 && !cmd[1].trim().isEmpty()) { // there are nonsense word after 'clean'
                throw new NahException(" Nahh!!! Do not type nonsense after 'clean' command\n");
            }
            return new Command.CleanCommand();
        }
        case "list": {
            if (cmd.length >= 2 && !cmd[1].trim().isEmpty()) { // there are nonsense word after 'list'
                throw new NahException(" Nahh!!! Do not type nonsense after 'list' command\n");
            }
            return new Command.ListCommand();
        }
        case "find": {
            if (cmd.length < 2) {
                return new Command.FindCommand("");
            }
            return new Command.FindCommand(cmd[1]);
        }
        case "mark": {
            if (cmd.length < 2) {
                throw new NahException(// No number for mark command
                        " Nah!!! Mark command needs a number\n");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) {
                throw new NahException(
                        " Nah.Nah!!! Please give me a valid ordinal number for the task\n");
            }
            return new Command.MarkCommand(i);
        }
        case "help": {
            return new Command.HelpCommand();
        }
        case "unmark": {
            if (cmd.length < 2) {
                throw new NahException(
                        " Nah!!! Unmark command needs a number\n");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) {
                throw new NahException(
                        " Nah.Nah!!! Please give me a valid ordinal number for the task\n");
            }
            return new Command.UnmarkCommand(i);
        }
        case "delete": {
            if (cmd.length < 2) {
                throw new NahException(" Nah!!! Delete command needs a number\n");
            }
            int i;
            try {
                i = parseInt(cmd[1]);
            } catch (NumberFormatException e) {
                throw new NahException(
                        " Nah.Nah!!! Please give me a valid ordinal number for the task\n");
            }
            return new Command.DeleteCommand(i);
        }
        case "dueon": {
            if (cmd.length < 2) {
                throw new NahException(
                        " Nah!!! DueOn command needs a time\n");
            }
            return new Command.DueOnCommand(cmd[1]);
        }
        case "todo": {
            if (cmd.length < 2 || cmd[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhh!!! Todo needs description\n");
            }
            return new Command.AddCommand(new ToDos(cmd[1].trim()));
        }
        case "deadline": {
            if (cmd.length < 2 || cmd[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhh!!! Deadline needs description\n");
            }
            String[] des = cmd[1].split("/by", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhhhhhh!!! Deadline needs deadline\n");
            }
            LocalDateTime by;
            try {
                by = LocalDateTime.parse(des[1].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
            } catch (DateTimeParseException e) {
                throw new NahException(
                        " Nahh!!! Time should be in the format yyyy-mm-dd hhmm, with valid date and time\n");
            }
            return new Command.AddCommand(new Deadlines(des[0].trim(), by));
        }
        case "event": {
            if (cmd.length < 2 || cmd[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhh!!! Event needs description\n");
            }
            String[] des = cmd[1].split("/from", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhhhhhh!!! Event needs starting time\n");
            }
            String[] time = des[1].split("/to", 2);
            if (time.length < 2 || time[1].trim().isEmpty()) {
                throw new NahException.LackDescriptionException(
                        " Nahhhhhhhhhhhh!!! Event needs ending time\n");
            }
            LocalDateTime start;
            LocalDateTime end;
            try {
                start = LocalDateTime.parse(time[0].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
                end = LocalDateTime.parse(time[1].trim(), DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
            } catch (DateTimeParseException e) {
                throw new NahException(
                        " Nahh!!! Time should be in the format yyyy-mm-dd hhmm, with valid date and time\n");
            }
            if (end.isBefore(start)) {
                throw new NahException(" Nah!!! Ending time should be after starting time.");
            }
            return new Command.AddCommand(new Events(des[0].trim(), start, end));
        }
        default: {
            return new Command.UnknownCommand();
        }
        }

    }

Example from src/main/java/nah/storage/Decoder.java lines 59-116:

    public static Task decode(String s) throws NahException {
        if (!checkFirstThreeComponent(s)) {
            throw new NahException.InvalidFileValueException();
        }

        String[] command = s.split("\\|", 3);
        if (command[0].trim().equals(TODO)) {
            Task t = new ToDos(command[2].trim());
            if (isDone(command[1])) {
                t.mark();
            }
            return t;
        }
        if (command[0].trim().equals(DEADLINE)) {
            String[] des = command[2].split("\\|", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.InvalidFileValueException();
            }
            try {
                LocalDateTime time = LocalDateTime
                        .parse(des[1].trim(), DateTimeFormatter.ofPattern(TIME_PATTERN));
                Task t = new Deadlines(des[0].trim(), time);
                if (isDone(command[1])) {
                    t.mark();
                }
                return t;
            } catch (DateTimeParseException e) {
                throw new NahException.InvalidFileValueException();
            }

        }

        if (command[0].trim().equals(EVENT)) {
            String[] des = command[2].split("\\|", 2);
            if (des.length < 2 || des[1].trim().isEmpty()) {
                throw new NahException.InvalidFileValueException();
            }
            String[] time = des[1].split("\\|", 2);
            if (time.length < 2 || time[1].trim().isEmpty()) {
                throw new NahException.InvalidFileValueException();
            }
            try {
                LocalDateTime start = LocalDateTime
                        .parse(time[0].trim(), DateTimeFormatter.ofPattern(TIME_PATTERN));
                LocalDateTime end = LocalDateTime
                        .parse(time[1].trim(), DateTimeFormatter.ofPattern(TIME_PATTERN));
                assert start.isBefore(end) : "Start time must be before End time";
                Task t = new Events(des[0].trim(), start, end);
                if (isDone(command[1])) {
                    t.mark();
                }
                return t;
            } catch (DateTimeParseException e) {
                throw new NahException.InvalidFileValueException();
            }
        }
        throw new NahException.InvalidFileValueException();
    }

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/nah/Nah.java lines 67-70:

    /**
     * main method
     * @param args
     */

Example from src/main/java/nah/gui/DialogBox.java lines 85-90:

    /**
     * return a DialogBox for user.
     * @param text corresponding text
     * @param img avatar for user
     * @return a DialogBox
     */

Example from src/main/java/nah/gui/DialogBox.java lines 95-100:

    /**
     * return a DialogBox for chatBot Nah.
     * @param text corresponding text
     * @param img avatar for Nah
     * @return a DialogBox
     */

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 4a0b2d0:


Make chatBot more user friendly by setting waiting time when closing
window screen


  • No blank line between subject and body

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 👍


❗ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant