Skip to content

Sharing iP code quality feedback [for @SwaminathanViswa] #5

Description

@nus-se-bot

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

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/bitbot/BitBot.java lines 28-125:

    public String getResponse(String input) {
        String finalResponse = null;
        StringBuilder from = new StringBuilder();
        StringBuilder to = new StringBuilder();
        StringBuilder by = new StringBuilder();
        String keyWord = null;
        String textPart = null;
        StringBuilder sb = new StringBuilder();

        int numberPart = -1;

        // this is to help check if the size is more than 1 or not
        // so that I can use the correct term (either "task" or "tasks")
        String task = !(arrayList.size() > 0) ? "task" : "tasks";

        try {
            String[] partsOfInput = input.split(" ");

            if (partsOfInput.length > 0) {
                keyWord = partsOfInput[0];

                switch (keyWord) {
                case "mark":
                    numberPart = TaskHandler.checkAndThrowExceptionForMarkUnmarkDelete(partsOfInput, arrayList);
                    finalResponse = handleMark(arrayList, numberPart);
                    break;
                case "unmark":
                    numberPart = TaskHandler.checkAndThrowExceptionForMarkUnmarkDelete(partsOfInput, arrayList);
                    finalResponse = handleUnmark(arrayList, numberPart);
                    break;
                case "delete":
                    numberPart = TaskHandler.checkAndThrowExceptionForMarkUnmarkDelete(partsOfInput, arrayList);
                    finalResponse = handleDelete(arrayList, numberPart, task);
                    break;
                case "find":
                    finalResponse = TaskHandler.handleFind(arrayList,
                            Arrays.copyOfRange(partsOfInput, 1, partsOfInput.length));
                    break;
                case "event":
                    finalResponse = handleEvent(arrayList, partsOfInput, task);
                    break;
                case "deadline":
                    finalResponse = handleDeadline(arrayList, partsOfInput, task);
                    break;
                case "todo":
                    finalResponse = handleTodo(arrayList, textPart, partsOfInput, sb, task);
                    break;
                case "list":
                    finalResponse = handleList(arrayList);
                    break;
                case "tag":
                    finalResponse = handleTag(arrayList, partsOfInput);
                    break;
                case "untag":
                    numberPart = TaskHandler.checkAndThrowExceptionForMarkUnmarkDelete(partsOfInput, arrayList);
                    finalResponse = handleUntag(arrayList, partsOfInput, numberPart);
                    break;
                case "bye":
                    Storage.saveTasksToFile(arrayList);
                    break;
                default:
                    // if it does not fall in any of this keyword,
                    // throw an error saying there is no such keyword.
                    throw new BitBotException("OOPS!!! I do not know what this keyword is!\n"
                            + "          Please key in only one of these:\n          "
                            + "\n          "
                            + "mark \n          "
                            + "unmark \n          "
                            + "todo \n          "
                            + "deadline \n          "
                            + "event\n          "
                            + "list\n          "
                            + "delete\n          "
                            + "bye\n          "
                            + "find\n          "
                            + "tag\n          "
                            + "untag\n          "
                            + "\n          "
                            + "Please key in in this format:\n          "
                            + "todo ... / deadline ... ");
                }

            } else {
                textPart = input.trim();
                keyWord = textPart;
            }

        } catch (BitBotException e) {
            finalResponse = "          ____________________________________\n"
                    + "          " + e.getMessage() + "\n"
                    + "          ____________________________________";
        } catch (IOException e) {
            finalResponse = "Error: " + e.getMessage();
        }

        return finalResponse;

    }

Example from src/main/java/bitbot/Storage.java lines 84-164:

    public static ArrayList<Task> readTasksFromFile(String filePath) throws FileNotFoundException {
        ArrayList<Task> listFromFile = new ArrayList<>();
        try {
            File file = new File(filePath);
            Scanner scanner = new Scanner(file);

            // adapted from W3.4c (using Scanner) of notes.
            while (scanner.hasNextLine()) {
                String[] partsOfLineFromFile = scanner.nextLine().split("\\|");
                Task task = null;

                // trims the trailing whitespace
                switch (partsOfLineFromFile[0].trim()) {
                case "D":
                    String descriptionOfDeadline = partsOfLineFromFile[2].trim();
                    String deadlineBy = partsOfLineFromFile[3].trim();
                    try {
                        LocalDateTime localDateTime = LocalDateTime.parse(deadlineBy, dateTimeFormatter);
                        task = new Deadline(descriptionOfDeadline, localDateTime);
                    } catch (DateTimeParseException e) {
                        try {
                            LocalDate localDate = LocalDate.parse(deadlineBy, dateFormatter);
                            task = new Deadline(descriptionOfDeadline, localDate);
                        } catch (DateTimeParseException err) {
                            try {
                                LocalTime localTime = LocalTime.parse(deadlineBy, timeFormatter);
                                task = new Deadline(descriptionOfDeadline, localTime);
                            } catch (DateTimeParseException error) {
                                task = new Deadline(descriptionOfDeadline, deadlineBy);
                            }
                        }
                    }
                    break;

                case "T":
                    task = new Todo(partsOfLineFromFile[2]);
                    break;

                case "E":
                    String descriptionOfEvent = partsOfLineFromFile[2].trim();
                    String eventFrom = partsOfLineFromFile[3].trim();
                    String eventTo = partsOfLineFromFile[4].trim();
                    try {
                        LocalDateTime localDateTime = LocalDateTime.parse(eventFrom, dateTimeFormatter);
                        LocalDateTime localDateTime1 = LocalDateTime.parse(eventTo, dateTimeFormatter);
                        task = new Events(descriptionOfEvent, localDateTime, localDateTime1);
                    } catch (DateTimeParseException e) {
                        try {
                            LocalDate localDate = LocalDate.parse(eventFrom, dateFormatter);
                            LocalDate localDate1 = LocalDate.parse(eventTo, dateFormatter);
                            task = new Events(descriptionOfEvent, localDate, localDate1);
                        } catch (DateTimeParseException err) {
                            try {
                                LocalTime localTime = LocalTime.parse(eventFrom, timeFormatter);
                                LocalTime localTime1 = LocalTime.parse(eventTo, timeFormatter);
                                task = new Events(descriptionOfEvent, localTime, localTime1);
                            } catch (DateTimeParseException error) {
                                task = new Events(descriptionOfEvent, eventFrom, eventTo);
                            }
                        }
                    }
                    break;
                default:
                }

                if (partsOfLineFromFile[1].trim().equals("X")) {
                    task.markAsDone();
                }
                if (!partsOfLineFromFile[partsOfLineFromFile.length - 1].trim().equals("")) {
                    task.markAsTagged(partsOfLineFromFile[partsOfLineFromFile.length - 1]);
                }
                listFromFile.add(task);
            }

            scanner.close();
        } catch (FileNotFoundException e) {
            System.out.println("File not found" + e.getMessage());
        }
        return listFromFile;

    }

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/bitbot/Storage.java lines 27-32:

    /**
     * It checks if the file that is being read from exists.
     * If it doesn't, create the directory and the file.
     *
     * @throws IOException if directory is not found.
     */

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


Add tagging function to Task.

The application does not have a functionality to tag tasks
to make it easier for identification and categorize them.

Users need a method to tag their tasks that they want.

Implement 'handleTag' and 'handleUntag' methods that allows users to
tag and untag tasks respectively.

This approach allows for proper input parsing and error handling.


  • Subject line should not end with a period

possible problems in commit efe167b:


The methods extractTimeDetail and extractDescription has for loops and
conditional statements to get the respective details.

The current implementation is harder to read and it is not as flexible
as compared to Java streams.

Change the two methods to use Java Streams for processing and getting
the necessary details.

Streams provide a variety of options and it makes the code more
readable and easier to maintain.


  • 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 👍


ℹ️ 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 cs2103@comp.nus.edu.sg if you want to follow up on this post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions