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 @lennoxtr] - Round 2 #4

Open
soc-se-bot-blue opened this issue Mar 14, 2023 · 0 comments
Open

Comments

@soc-se-bot-blue
Copy link

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

Example from src/main/java/duke/io/input/ui/ChatBot.java lines 25-25:

    private boolean usedByUser;

Example from src/main/java/duke/workflow/DoTask.java lines 24-24:

    private boolean justOpenedDuke;

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/duke/io/input/ui/MainWindow.java lines 124-170:

    private void handleUserInput() {
        if (this.firstTimeRunningDukeFlag < 0) {
            firstTimeRunningDukeFlag = runDuke();

        } else if (firstTimeRunningDukeFlag > 0) {
            if (!this.currentEvent.isFinalEvent()) {
                String input = userInput.getText();
                userInput.clear();
                TaskList currentTaskList = this.currentEvent.getTaskList();
                boolean validInput = Parser.checkInputValidity(input, currentTaskList.getSize());
                this.currentEvent = this.currentEvent.toNextEvent(input);

                dialogContainer.getChildren().addAll(
                        DialogBox.getUserDialog(input, userImage));

                if (!validInput) {
                    String warning = Parser.getWarningGui(input, currentTaskList.getSize());
                    dialogContainer.getChildren().addAll(
                            DialogBox.getDukeDialog(warning, dukeImage));
                }

                dialogContainer.getChildren().addAll(
                        DialogBox.getDukeDialog(this.currentEvent.toString(), dukeImage));

                if (this.currentEvent.isFinalEvent()) {
                    String saveProgressQuery = "SAVE YOUR GRAND PLAN FOR ANOTHER DAY? ";
                    dialogContainer.getChildren().add(
                            DialogBox.getDukeDialog(saveProgressQuery, dukeImage));
                }
            } else {
                String input = userInput.getText();
                userInput.clear();

                dialogContainer.getChildren().addAll(
                        DialogBox.getUserDialog(input, userImage));

                Storage.saveProgressGui(input, this.currentEvent.getTaskList());
                if (input.equals("YES")) {
                    dialogContainer.getChildren().addAll(
                            DialogBox.getDukeDialog("[X] FILE CREATED", dukeImage),
                            DialogBox.getDukeDialog("[X] FILE SAVED", dukeImage));
                }
            }
        } else {
            return;
        }
    }

Example from src/main/java/duke/util/Storage.java lines 276-318:

    private void addTaskToSchedule(Task task) {
        List<LocalDateTime> eventDates = task.getDates();

        if (task.getNature().equals("DEADLINE")) {
            LocalDateTime deadlineDate = eventDates.get(0);
            LocalDate convertedDate = deadlineDate.toLocalDate();

            String date = convertedDate.toString();
            PriorityQueue<Pair<LocalDateTime, Task>> currentQueue;

            if (this.taskScheduleOnDates.containsKey(date)) {
                currentQueue = this.taskScheduleOnDates.get(date);
            } else {
                currentQueue = new PriorityQueue<>(new DatetimeComparator());
            }
            currentQueue.add(new Pair<LocalDateTime, Task>(deadlineDate, task));
            this.taskScheduleOnDates.put(date, currentQueue);

        } else if (task.getNature().equals("EVENT")) {

            LocalDateTime dateBeginUnformatted = eventDates.get(0);
            LocalDate dateBeginFormatted = dateBeginUnformatted.toLocalDate();

            LocalDateTime dateEndUnformatted = eventDates.get(1);
            LocalDate dateEndFormatted = dateEndUnformatted.toLocalDate();

            while (dateBeginFormatted.compareTo(dateEndFormatted) <= 0) {
                String searchDate = dateBeginFormatted.toString();
                PriorityQueue<Pair<LocalDateTime, Task>> currentQueue;
                if (this.taskScheduleOnDates.containsKey(searchDate)) {
                    currentQueue = this.taskScheduleOnDates.get(searchDate);
                } else {
                    currentQueue =
                            new PriorityQueue<>(new DatetimeComparator());
                }
                currentQueue.add(new Pair<LocalDateTime, Task>(dateBeginUnformatted, task));
                this.taskScheduleOnDates.put(searchDate, currentQueue);
                dateBeginFormatted = dateBeginFormatted.plusDays(1);
            }
        } else {
            return;
        }
    }

Example from src/main/java/duke/workflow/DoTask.java lines 93-135:

    public Event toNextEvent(String userCommand) {
        this.justOpenedDuke = false;
        if (userCommand.equals("BYE")) {
            this.userCommand = userCommand;
            return new Ending(this.taskList);
        } else if (userCommand.equals("LIST")) {
            this.userCommand = userCommand;
            return this;
        } else if (Parser.checkInputValidity(userCommand, this.taskList.getSize())) {
            this.userCommand = userCommand;
            String[] userInputArray = userCommand.split(" ");
            List<String> userInputSplit = Arrays.asList(userInputArray);
            String mainCommand = userInputSplit.get(0);

            if (mainCommand.equals("MARK")) {
                int indexOfTask = Integer.valueOf(userInputSplit.get(1)) - 1;
                assert (userInputSplit.size() > 0);
                this.taskList = this.taskList.markTask(indexOfTask);
                assert (this.taskList.getTask(indexOfTask).getStatus() == true);
            } else if (mainCommand.equals("UNMARK")) {
                int indexOfTask = Integer.valueOf(userInputSplit.get(1)) - 1;
                assert (userInputSplit.size() > 0);
                this.taskList = this.taskList.unmarkTask(indexOfTask);
                assert (this.taskList.getTask(indexOfTask).getStatus() == false);
            } else if (mainCommand.equals("TODO") || mainCommand.equals("DEADLINE")
                    || mainCommand.equals("EVENT")) {
                parseTask(userCommand);
            } else if (mainCommand.equals("DELETE")) {
                int indexOfTask = Integer.valueOf(userInputSplit.get(1)) - 1;
                this.removedTask = this.taskList.getTask(indexOfTask);
                this.taskList = this.taskList.removeTask(indexOfTask);
                this.storage = this.storage.removeFromStorage(this.removedTask);
            } else if (mainCommand.equals("FIND")) {
                String[] keywordToFind = userCommand.split("FIND ");
                List<String> keywords = Arrays.asList(keywordToFind);
                TaskList findList = this.storage.getTaskWithKeywords(keywords.get(1));
                this.taskListFromCommand = findList;
            } else if (mainCommand.equals("SCHEDULE")) {
                findTaskOnDate(userCommand);
            }
        }
        return this;
    }

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/duke/Duke.java lines 6-10:

    /**
     * Initialize Duke chatbot and begin chatting with user.
     *
     * @param args
     */

Example from src/main/java/duke/io/input/ui/MainWindow.java lines 42-44:

    /**
     * Construct a MainWindow class containingan AnchorPane, VBox, ScrollPane, TextField, and Button
     */

Example from src/main/java/duke/util/Task.java lines 75-79:

    /**
     * Return the marking status of an event
     *
     * @return the marking status of an event
     */

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 (Subject Only)

possible problems in commit 5e7e644:

Fixed window auto resizing after input

  • Not in imperative mood (?)

Suggestion: Follow the given conventions for Git commit messages for future commits (no need to modify past commit messages).

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