Giter Club home page Giter Club logo

ip's Issues

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

@Ella-e 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/duke/Duke.java lines 67-121:

    public String getResponse(String userInput) {
        String response = "";
        try {
            // use parser to process the userInput
            // the parser object contains all the current user input line information
            Parser parser = new Parser();
            parser.parse(userInput);

            // check for end the session
            if (parser.getCurrentKey().equals(KeyEnum.EXITKEY)) {
                response = ui.onExit();
            }

            // continue for the functionality
            switch (parser.getCurrentKey()) {
            case DEADLINE:
            case TODO:
            case EVENT:
                Task task = tasks.addTask(parser.getInputDetail(),
                    parser.getFrom(), parser.getTo(), parser.getCurrentKey());
                storage.writeTasksToFile(tasks);
                response = ui.onAddSuccess(task, tasks.getNumOfTasks());
                break;
            case LIST:
                response = ui.showList(tasks);
                break;
            case MARK:
                Task markedTask = tasks.markTaskById(parser.getIndex(), true);
                storage.writeTasksToFile(tasks);
                response = ui.onMarkDone(markedTask);
                break;
            case UNMARK:
                Task unMarkedTask = tasks.markTaskById(parser.getIndex(), false);
                storage.writeTasksToFile(tasks);
                response = ui.onUnmarkDone(unMarkedTask);
                break;
            case DELETE:
                Task deletedTask = tasks.deleteTaskById(parser.getIndex());
                storage.writeTasksToFile(tasks);
                response = ui.onDelete(deletedTask, tasks);
                break;
            case FIND:
                TaskList matchedTasks = tasks.findTasks(parser.getInputDetail());
                response = ui.showMatchedList(matchedTasks);
                break;
            default:
                break;
            }
        } catch (BaseException e) {
            response = ui.showErrorMsg(e.getMessage());
        } catch (IOException e) {
            response = ui.showLoadingError();
        }
        return response;
    }

Example from src/main/java/duke/tasks/TaskList.java lines 157-201:

    public TaskList findNextDueTasks(int numOfTasks) {
        ArrayList<Task> nextTasks = new ArrayList<>(tasks);
        nextTasks.removeIf(Task::getIsDone); // remove completed tasks
        nextTasks.sort(new Comparator<Task>() {
            @Override
            public int compare(Task o1, Task o2) {
                if (o1 instanceof Todo) {
                    return 1;
                }
                if (o2 instanceof Todo) {
                    return -1;
                }

                if (o1 instanceof Deadline) {
                    if (o2 instanceof Deadline) {
                        return ((Deadline) o1).getBy().compareTo(((Deadline) o2).getBy());
                    } else if (o2 instanceof Event) {
                        return ((Deadline) o1).getBy().compareTo(((Event) o2).getBy());
                    }
                } else if (o1 instanceof Event) {
                    if (o2 instanceof Deadline) {
                        return ((Event) o1).getBy().compareTo(((Deadline) o2).getBy());
                    } else if (o2 instanceof Event) {
                        return ((Event) o1).getBy().compareTo(((Event) o2).getBy());
                    }
                }
                return 0;
            }
        });

        if (nextTasks.size() <= numOfTasks) {
            return new TaskList(nextTasks);
        }

        ArrayList<Task> tempTasks = new ArrayList<>();
        int counter = numOfTasks;
        for (Task task: nextTasks) {
            if (counter <= 0) {
                break;
            }
            tempTasks.add(task);
            counter--;
        }
        return new TaskList(tempTasks);
    }

Example from src/main/java/duke/utils/Parser.java lines 32-95:

    public void parse(String userInput) throws InvalidKeyException, EmptyBodyException,
            WrongFormatException, InvalidNumberException, DateTimeParseException, InvalidDateTimeException {
        String[] userInputSplit = userInput.split(" ");
        // verify that the user input is valid
        String checkInputMsg = checkSpecialCharacter(userInputSplit);
        if (!checkInputMsg.equals("valid")) {
            throw new WrongFormatException(checkInputMsg);
        }
        this.determineCurrentKey(userInputSplit[0]);
        switch (this.currentKey) {
        case DEADLINE:
            if (userInput.length() <= 9) {
                throw new EmptyBodyException();
            }
            try {
                inputDetail = userInput.substring(9, userInput.indexOf("/by"));
                to = formatDate(userInput.substring(userInput.indexOf("/by") + 4));
            } catch (Exception e) {
                throw new WrongFormatException("\"deadline content /by yyyy-mm-dd\"");
            }
            break;
        case TODO:
        case FIND:
            if (userInput.length() <= 5) {
                throw new EmptyBodyException();
            }
            inputDetail = userInput.substring(5);
            break;
        case EVENT:
            if (userInput.length() <= 6) {
                throw new EmptyBodyException();
            }
            try {
                inputDetail = userInput.substring(6, userInput.indexOf("/from"));
                from = formatDate(userInput.substring(userInput.indexOf("/from") + 6, userInput.indexOf("/to") - 1));
                to = formatDate(userInput.substring(userInput.indexOf("/to") + 4));
                if (from.isAfter(to)) {
                    throw new InvalidDateTimeException("The start date should be before the end date");
                }
            } catch (InvalidDateTimeException e) {
                throw e;
            } catch (Exception e) {
                throw new WrongFormatException("\"event content /from yyyy-mm-dd /to yyyy-mm-dd\"");
            }
            break;
        case MARK:
        case UNMARK:
        case DELETE:
            try {
                this.index = new Integer(userInputSplit[1]) - 1;
                this.inputDetail = this.index.toString();
            } catch (Exception e) {
                throw new InvalidNumberException();
            }
            break;
        default:
            break;
        }

        // check if the user input contains only empty spaces.
        if (!(currentKey.equals(KeyEnum.LIST) || currentKey.equals(KeyEnum.EXITKEY)) && inputDetail.trim().isEmpty()) {
            throw new EmptyBodyException();
        }
    }

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

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.

Sharing iP code quality feedback [for @Ella-e]

@Ella-e 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/tasks/Task.java lines 7-7:

    private Boolean status;

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

No easy-to-detect issues ๐Ÿ‘

Aspect: Class size

No easy-to-detect issues ๐Ÿ‘

Aspect: Header Comments

Example from src/main/java/duke/Duke.java lines 61-64:

    /**
     * You should have your own function to generate a response to user input.
     * Replace this stub with your completed method.
     */

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 ea64415:


Merge branch 'master' into branch-B-Reminders
Update with master


  • No blank line between subject and body

possible problems in commit d9eaeaf:


Merge branch 'master' into branch-B-Reminders
Update with master


  • No blank line between subject and body

possible problems in commit 46f0322:


Merge branch 'master' into branch-A-CI
Update with master


  • 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

Suggestion: Avoid committing binary files (e.g., *.class, *.jar, *.exe) or third-party library files in to the repo.


โ„น๏ธ 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.