Skip to content

Sharing iP code quality feedback [for @bryanckh] #1

@nus-se-bot

Description

@nus-se-bot

@bryanckh 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/beechat/Beechat.java lines 11-121:

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("MMM dd yyyy HHmm");
        System.out.println("Hello! I'm Beechat!\nWhat can I do for you?\n");
        ArrayList<Task> tasks = new ArrayList<>(FileHandler.loadTasks());
        String msg = sc.nextLine();
        Task task;
        int j;
        while (!msg.equals("bye")) {
            String start = (msg.split(" "))[0];
            if (start.equals("list")) {
                for (int i = 0; i < tasks.size(); i++) {
                    System.out.println(String.format("%d. %s", i + 1, tasks.get(i)));
                }
                msg = sc.nextLine();
                continue;
            }
            if (start.equals("delete")) {
                try {
                    j = Integer.parseInt(msg.split(" ")[1]) - 1;
                    Task removedTask = tasks.remove(j);
                    System.out.println("OK, I've removed this task:\n" + removedTask);
                    FileHandler.saveTasks(tasks);
                } catch (ArrayIndexOutOfBoundsException e) {
                    System.out.println("Please delete in this form: \n" +
                            "delete [integer]");
                } catch (IndexOutOfBoundsException e) {
                    System.out.println("Please enter a valid index" );
                }
                msg = sc.nextLine();
                continue;
            }
            if (start.equals("mark")) {
                try {
                    j = Integer.parseInt(msg.split(" ")[1]) - 1;
                    tasks.get(j).mark();
                    System.out.println("Nice! I've marked this task as done:\n" + tasks.get(j));
                    FileHandler.saveTasks(tasks);
                } catch (ArrayIndexOutOfBoundsException e) {
                    System.out.println("Please mark in this form: \n" +
                            "mark [index]");
                } catch (IndexOutOfBoundsException e) {
                    System.out.println("Please enter a valid index" );
                }
                msg = sc.nextLine();
                continue;
            }
            if (start.equals("unmark")) {
                try {
                    j = Integer.parseInt(msg.split(" ")[1]) - 1;
                    tasks.get(j).unmark();
                    System.out.println("OK, I've marked this task as not done yet:\n" + tasks.get(j));
                    FileHandler.saveTasks(tasks);
                } catch (ArrayIndexOutOfBoundsException e) {
                    System.out.println("Please unmark in this form: \n" +
                            "unmark [integer]");
                } catch (IndexOutOfBoundsException e) {
                    System.out.println("Please enter a valid index" );
                }
                msg = sc.nextLine();
                continue;
            }
            if (start.equals("todo")) {
                try {
                    String description = (msg.split("todo "))[1];
                    task = new TodoTask(description);
                    tasks.add(task);
                    System.out.println("added: " + description);
                    FileHandler.saveTasks(tasks);
                } catch (IndexOutOfBoundsException e) {
                    System.out.println("Please enter the todo task in this form: \n" +
                            "todo [task name]");
                }
            }
            if (start.equals("deadline")) {
                try {
                    String description = ((msg.split("deadline "))[1]).split("/by ")[0];
                    LocalDateTime by = LocalDateTime.parse((msg.split("/by "))[1], inputFormatter);
                    task = new DeadlineTask(description, by);
                    tasks.add(task);
                    System.out.println("added: " + description);
                    FileHandler.saveTasks(tasks);
                } catch (IndexOutOfBoundsException e) {
                    System.out.println("Please enter the deadline task in this form: \n" +
                            "deadline [task name] /by [deadline]");
                } catch (DateTimeParseException e) {
                    System.out.println("Please enter the deadline in this form: \n" +
                            "MMM dd yyyy HHmm");
                }
            }
            if (start.equals("event")) {
                try {
                    String description = ((msg.split("event "))[1]).split("/from ")[0];
                    LocalDateTime from = LocalDateTime.parse((msg.split("/from "))[1].split(" /to ")[0], inputFormatter);
                    LocalDateTime to = LocalDateTime.parse((msg.split("/to "))[1], inputFormatter);
                    task = new EventTask(description, from, to);
                    tasks.add(task);
                    System.out.println("added: " + description);
                    FileHandler.saveTasks(tasks);
                } catch (IndexOutOfBoundsException e) {
                    System.out.println("Please enter the event task in this form: \n" +
                            "event [task name] /from [date and starttime] /by [date and endtime]");
                } catch (DateTimeParseException e) {
                    System.out.println("Please enter the from and to in this form: \n" +
                            "MMM dd yyyy HHmm");
                }
            }
            msg = sc.nextLine();
        }
        System.out.println("Bye. Hope to see you again soon!");
    }

Example from src/main/java/beechat/FileHandler.java lines 15-72:

    public static List<Task> loadTasks() {
        List<Task> tasks = new ArrayList<>();
        File file = new File(FILE_PATH);

        try {
            if (!file.exists()) {
                new File("./data").mkdirs(); // Create the directory if it doesn't exist
                file.createNewFile(); // Create the file if it doesn't exist
            } else {
                BufferedReader reader = new BufferedReader(new FileReader(FILE_PATH));
                String line;
                while ((line = reader.readLine()) != null) {
                    String[] parts = line.split(" \\| ");
                    String taskType = parts[0];
                    boolean isDone = parts[1].equals("1");
                    String description = parts[2];

                    switch (taskType) {
                        case "T":
                            Task todo = new TodoTask(description);
                            if (isDone) {
                                todo.mark();
                            }
                            tasks.add(todo);
                            break;
                        case "D":
                            try {
                                LocalDateTime by = LocalDateTime.parse(parts[3], FORMATTER);
                                Task deadline = new DeadlineTask(description, by);
                                if (isDone) deadline.mark();
                                tasks.add(deadline);
                            } catch (DateTimeParseException e) {
                                System.out.println("Error when parsing date for deadline task: " + e.getMessage());
                            }
                            break;
                        case "E":
                            try {
                                LocalDateTime from = LocalDateTime.parse(parts[3], FORMATTER);
                                LocalDateTime to = LocalDateTime.parse(parts[4], FORMATTER);
                                Task event = new EventTask(description, from, to);
                                if (isDone) event.mark();
                                tasks.add(event);
                            } catch (DateTimeParseException e) {
                                System.out.println("Error when parsing date for event task: " + e.getMessage());
                            }
                            break;
                        default:
                            throw new IOException("Invalid task type in file: " + taskType);
                    }
                }
                reader.close();
            }
        } catch (IOException e) {
            System.out.println("Error loading tasks: " + e.getMessage());
        }

        return tasks;
    }

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 5b6c936:


A-TextUiTesting


  • Not in imperative mood (?)

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