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 @btbrandon] - Round 2 #5

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

Comments

@nus-se-script
Copy link

@btbrandon 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/BeeBot.java lines 47-146:

    public static String getResponse(String input) {
        String[] parts = input.split(" ");
        String cmd = parts[0];
        try {
            switch (cmd) {
            case "list":
                int size = taskList.size();
                if (size == 0) return "There is currently nothing on the list!";
                String listStr = "";
                for (int i = 0; i < size; i++) {
                    int num = i + 1;
                    listStr += (num + "." + taskList.get(i).toString());
                }
                return listStr;
            case "mark":
                assert Integer.parseInt(parts[1]) > 0 && Integer.parseInt(parts[1]) <= taskList.size() : "Task number is out of range";
                Task doneTask = Parser.getTask(taskList, Integer.parseInt(parts[1]));
                doneTask.markAsDone();
                storage.saveTaskListToFile(taskList);
                return "🐝-utiful! Honeyboo marked this task as done:\n" + doneTask;
            case "unmark":
                assert Integer.parseInt(parts[1]) > 0 && Integer.parseInt(parts[1]) <= taskList.size() : "Task number is out of range";
                Task undoneTask = Parser.getTask(taskList, Integer.parseInt(parts[1]));
                undoneTask.markAsUndone();
                storage.saveTaskListToFile(taskList);
                return "🐝-utiful! Honeyboo marked this task as not done yet:\n" + undoneTask;
            case "todo":
                if (parts.length == 1) throw new EmptyDescriptionException("Enter a description for the Todo Task.\n");
                String todoName = Parser.concatenate(parts, 1);
                TaskList.createToDo(todoName, taskList);
                storage.saveTaskListToFile(taskList);
                return "Growl... Honeyboo added '" + todoName + "' to the list!";
            case "deadline":
                if (parts.length == 1) throw new EmptyDescriptionException("Enter a description for the Deadline Task.\n");
                String deadlineName = Parser.concatenateUntil(parts, "/by");
                String deadlineDate = Parser.dateConverter(Parser.getFollowingDate(parts, "/by"));
                TaskList.createDeadline(deadlineName, deadlineDate, taskList);
                storage.saveTaskListToFile(taskList);
                return "BZZZZZ... Honeyboo added  '"  + deadlineName + "' to the list!";
            case "event":
                if (parts.length == 1) throw new EmptyDescriptionException("Enter a description for the Event Task.\n");
                String eventName = Parser.concatenateUntil(parts, "/from");
                String startTime = Parser.dateConverter(Parser.getFollowingDate(parts, "/from", "/to"));
                String endTime = Parser.dateConverter(Parser.getFollowingDate(parts, "/to", ""));
                TaskList.createEvent(eventName, startTime, endTime, taskList);
                storage.saveTaskListToFile(taskList);
                return "Grrrr... Honeyboo added '" + eventName + "' to the list!";
            case "delete":
                assert Integer.parseInt(parts[1]) - 1 >= 0 && Integer.parseInt(parts[1]) - 1 < taskList.size() : "Task number is out of range";
                TaskList.deleteEvent(Integer.parseInt(parts[1]) - 1, taskList);
                storage.saveTaskListToFile(taskList);
                return "Yum yum in my tum tum! Task eaten!";
            case "find":
                String taskName = Parser.concatenate(parts, 1);
                ArrayList<Task> searchResults = new ArrayList<>();
                for (Task task: taskList) {
                    if (task.getName().contains(taskName)) {
                        searchResults.add(task);
                    }
                }
                int searchSize = searchResults.size();
                String searchStr = "";
                for (int i = 0; i < searchSize; i++) {
                    int num = i + 1;
                    searchStr += (num + "." + searchResults.get(i).toString());
                }
                return searchStr;
            case "update":
                String updateTo = Parser.getUpdatedName(parts);
                TaskList.updateTask(Integer.parseInt(parts[1]) - 1, updateTo, taskList);
                storage.saveTaskListToFile(taskList);
                return "Task updated!";
            case "bye":
                System.exit(0);
                return "Goodbye! The application will now close.";
            default:
                return """
                        Please enter a valid command for worker bee to follow:
                        1. todo <task name>
                        2. deadline <task name> /by <due date>
                        3. event <task-name> /from <start date> /to <end date>
                        4. mark <index>
                        5. unmark <index>
                        6. list
                        7. find <part of task name>
                        8. update <task number> /to <new name>
                        9. delete <task number>
                        9. bye""";
            }
        } catch (EmptyDescriptionException | MissingDeadlineException
                 | MissingEventTimeException | TaskNotFoundException e) {
           return e.getMessage();
        } catch (DateTimeParseException e) {
            return "Invalid date format. Enter date in YYYY-MM-DD format";
        } catch (NumberFormatException e) {
            return "Please enter a valid task number.\n";
        } catch (Exception e) {
            return "An error occurred: " + e.getMessage() + e + "\n";
        }
    }

Example from src/main/java/storage/Storage.java lines 33-83:

    public ArrayList<Task> loadTaskListFromFile() {
        ArrayList<Task> taskList = new ArrayList<>();
        File file = new File(filePath);
        if (!file.exists()) {
            try {
                File dir = new File(file.getParent());
                if (!dir.exists()) {
                    dir.mkdir();
                }
                file.createNewFile();
            } catch (IOException e) {
                System.out.println("An error occurred while creating the file: " + e.getMessage());
                return null;
            }
        }

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(" \\| ");
                String type = parts[0];
                boolean isDone = parts[1].equals("1");
                String description = parts[2];

                switch (type) {
                case "ToDo":
                    ToDo todo = new ToDo(description);
                    if (isDone) todo.markAsDone();
                    taskList.add(todo);
                    break;
                case "Deadline":
                    String by = parts[3];
                    Deadline deadline = new Deadline(description, by);
                    if (isDone) deadline.markAsDone();
                    taskList.add(deadline);
                    break;
                case "Event":
                    String from = parts[3];
                    String to = parts[4];
                    Event event = new Event(description, from, to);
                    if (isDone) event.markAsDone();
                    taskList.add(event);
                    break;
                }
            }
        } catch (IOException e) {
            System.out.println("An error occurred while loading the task list: " + e.getMessage());
            return null;
        }
        return taskList;
    }

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

possible problems in commit fc71600:


Add update function to BeeBot class to allow updating names

This increases flexibility for users by allowing them to directly edit the names of previously added tasks.


  • body not wrapped at 72 characters: e.g., This increases flexibility for users by allowing them to directly edit the names of previously added tasks.

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