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 @elaineshijie] #3

Open
nus-se-script opened this issue Sep 16, 2023 · 0 comments
Open

Sharing iP code quality feedback [for @elaineshijie] #3

nus-se-script opened this issue Sep 16, 2023 · 0 comments

Comments

@nus-se-script
Copy link

@elaineshijie 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/seedu/duke/datafile/Storage.java lines 88-147:

    public ArrayList<Task> loadFile() throws LemonException {
        ArrayList<Task> tasks = new ArrayList<>();
        File dataFile = new File(filePath);
        Scanner scanner;
        // if there is no storage - no tasks
        if (!dataFile.exists()) {
            System.out.println("File doesn't exist?");
            return tasks;
        } else {
            try {
                scanner = new Scanner(dataFile);
                while (scanner.hasNextLine()) {
                    System.out.println("checking line by line");
                    String[] input = scanner.nextLine().split(" \\| ");
                    String taskType = input[0];
                    System.out.println(taskType);
                    switch(taskType) {
                    case "T":
                        boolean isDoneT = checkDone(input[1]);
                        String descriptionT = input[2];
                        Task toAddTaskT = new Todo(descriptionT, isDoneT);
                        tasks.add(toAddTaskT);
                        System.out.println("Added" + descriptionT);
                        break;
                    case "D":
                        boolean isDoneD = checkDone(input[1]);
                        String descriptionD = input[2];
                        String by = input [3];
                        try {
                            Task toAddTaskD = new Deadline(descriptionD, by, isDoneD);
                            tasks.add(toAddTaskD);
                            System.out.println("Added" + descriptionD);
                        } catch (InvalidDeadlineException e) {
                            System.out.println(e.getMessage());
                        }
                        break;
                    case "E":
                        boolean isDoneE = checkDone(input[1]);
                        String descriptionE = input[2];
                        String fromE = input[3];
                        String toE = input[4];
                        try {
                            Task toAddTaskE = new Event(descriptionE, fromE, toE, isDoneE);
                            tasks.add(toAddTaskE);
                            System.out.println("Added" + descriptionE);
                        } catch (InvalidEventException e) {
                            System.out.println(e.getMessage());
                        }
                        break;
                    default:
                        throw new LemonException("Failure to load file!");
                    }
                }
            } catch (FileNotFoundException e) {
                System.out.println("File not foudn grrr");
                throw new LemonException("Storage file not available!");
            }
        }
        return tasks;
    }

Example from src/main/java/seedu/duke/parser/Parser.java lines 50-176:

    public static String parseTasks(String input, TaskList tasks, Storage tasksData, Ui ui) throws LemonException {
        System.out.println("input is: " + input);
        if (!input.equals("bye")) {
            String commandType = input.split(" ")[0].toUpperCase();
            try {
                Commands command = Commands.valueOf(commandType);
                switch (command) {
                case LIST:
                    if (tasks.getTasksSize() < 1) {
                        System.out.println("No tasks??");
                        throw new NoTasksException("");
                    }
                    return ui.listAll(tasks);

                case MARK:
                    try {
                        int indexToMark = Integer.valueOf(input.split(" ")[1]);
                        String taskDescription = tasks.markTask(indexToMark - 1);
                        tasksData.saveTasks(tasks.getTaskList());
                        return ui.markPrint(taskDescription, tasks);
                    } catch (IndexOutOfBoundsException e) {
                        throw new InvalidTaskIndexException("");
                    }
                case UNMARK:
                    try {
                        int indexToUnmark = Integer.valueOf(input.split(" ")[1]);
                        String unmarkTaskDescription = tasks.unmarkTask(indexToUnmark - 1);
                        tasksData.saveTasks(tasks.getTaskList());
                        return ui.unmarkPrint(unmarkTaskDescription, tasks);

                    } catch (IndexOutOfBoundsException e) {
                        throw new InvalidTaskIndexException("");
                    }
                case TODO:
                    String[] taskSplit = input.split(" ", 2);
                    if (taskSplit.length < 2) {
                        throw new InvalidTodoException("");
                    }
                    String taskDescription = taskSplit[1];
                    String taskDescriptionTodo = tasks.addTasks(new Todo(taskDescription));
                    tasksData.saveTasks(tasks.getTaskList());
                    return ui.addTasks(taskDescriptionTodo, tasks);

                case DEADLINE:
                    String task = input.split(" ", 2)[1];
                    String[] getDeadlineArray = task.split("/by ", 2);
                    if (getDeadlineArray.length < 2) {
                        throw new InvalidDeadlineException("");
                    }
                    String taskDesc = getDeadlineArray[0];
                    String by = getDeadlineArray[1];
                    Task newDeadlineTask = new Deadline(taskDesc, by);
                    String taskDescriptionDeadline = tasks.addTasks(newDeadlineTask);
                    tasksData.saveTasks(tasks.getTaskList());
                    return ui.addTasks(taskDescriptionDeadline, tasks);

                case EVENT:
                    String inputTask = input.split(" ", 2)[1];
                    String[] getEventFromArray = inputTask.split("/from ", 2);
                    if (getEventFromArray.length < 2) {
                        throw new InvalidEventException("");
                    }
                    String taskDetails = getEventFromArray[0];
                    String[] getEventToArray = getEventFromArray[1].split(" /to ", 2);
                    if (getEventToArray.length < 2) {
                        throw new InvalidEventException("");
                    }
                    String from = getEventToArray[0];
                    String to = getEventToArray[1];
                    Task newEventTask = new Event(taskDetails, from, to);
                    String taskDescriptionEvent = tasks.addTasks(newEventTask);
                    tasksData.saveTasks(tasks.getTaskList());
                    return ui.addTasks(taskDescriptionEvent, tasks);

                case DELETE:
                    int inputDelete = Integer.valueOf(input.split(" ", 2)[1]) - 1;
                    try {
                        Task taskToDelete = tasks.getTask(inputDelete);
                        String taskDescriptionDelete = tasks.deleteTask(taskToDelete);
                        tasksData.saveTasks(tasks.getTaskList());
                        return ui.deletePrint(taskDescriptionDelete, tasks);
                    } catch (IndexOutOfBoundsException e) {
                        throw new InvalidTaskIndexException("");
                    }

                case FIND:
                    String[] commandSplit = input.split(" ", 2);
                    if (commandSplit.length < 2) {
                        throw new KeywordNotFoundException("No Keywords to find!");
                    }
                    String keyword = input.split(" ")[1];
                    ArrayList<Task> matchingTasks = tasks.findKeyword(keyword);
                    if (matchingTasks.size() == 0) {
                        throw new KeywordNotFoundException("No Tasks found!");
                    }
                    return ui.listMatching(matchingTasks);
                case RESCHEDULE:
                    try {
                        System.out.println("rescheduling!");
                        String[] indexTask = input.split(" ", 2);
                        if (indexTask.length < 2) {
                            throw new LemonException("Please include a task number & date to reschedule to!");
                        }
                        String[] getRescheduleTask = indexTask[1].split(" /to ", 2);

                        if (getRescheduleTask.length < 2) {
                            throw new LemonException("Please include a date to reschedule to with /to!");
                        }
                        int indexToReschedule = Integer.valueOf(getRescheduleTask[0]) - 1;
                        String rescheduleDate = getRescheduleTask[1];
                        tasks.rescheduleTask(indexToReschedule, rescheduleDate);
                        System.out.println(rescheduleDate);
                        tasksData.saveTasks(tasks.getTaskList());
                        String rescheduleTaskDescription = tasks.getTask(indexToReschedule).toString();
                        return ui.rescheduleDeadline(rescheduleTaskDescription, tasks);
                    } catch (IndexOutOfBoundsException e) {
                        throw new InvalidTaskIndexException("");
                    }
                default:
                    throw new InvalidTaskException(" " + input + " ");
                }
            } catch (IllegalArgumentException e) {
                throw new InvalidTaskException(" " + input + " ");
            }
        }
        return ui.bye();
    }

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/seedu/duke/Duke.java lines 67-69:

    /**
     * Run the chatbot named Lemon.
     */

Example from src/main/java/seedu/duke/Duke.java lines 90-93:

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

Example from src/main/java/seedu/duke/MainWindow.java lines 63-65:

    /**
     * To display the welcome message in a dialog box when Lemon is activated.
     */

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 38d2045:


Add reschedule commands to deadline tasks.

Users cannot reschedule their deadline tasks.

A reschedule command is more user-friendly because users can change the deadline of the tasks without having to delete the task and adding it with another deadline.


  • Subject line should not end with a period
  • body not wrapped at 72 characters: e.g., A reschedule command is more user-friendly because users can change the deadline of the tasks without having to delete the task and adding it with another deadline.

possible problems in commit 40c510e:


Add necessary Javadocs & changes to adhere to quality code standards.


  • Subject line should not end with a period

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 👍


ℹ️ 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