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 @timothysashimi] - Round 2 #25

Open
soc-se-bot-blue opened this issue Mar 19, 2024 · 0 comments
Open

Comments

@soc-se-bot-blue
Copy link

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

Example from src/main/java/duke/Toothless.java lines 50-51:

        }
        catch (FileNotFoundException e) {

Suggestion: As specified by the coding standard, use egyptian style braces.

Aspect: Package Name Style

No easy-to-detect issues 👍

Aspect: Class Name Style

No easy-to-detect issues 👍

Aspect: Dead Code

Example from src/main/java/duke/Parser.java lines 26-26:

    //String response;

Example from src/main/java/duke/Parser.java lines 29-29:

        //this.response = "";

Example from src/main/java/duke/Storage.java lines 62-62:

                //System.out.println("1");

Suggestion: Remove dead code from the codebase.

Aspect: Method Length

Example from src/main/java/duke/Parser.java lines 40-85:

    public Pair<TaskList, String> parse(TaskList tasksList, String input) throws InvalidInstructionException {
        String output = "";
        if (!input.toLowerCase().equals("bye")) {

            if (input.equals("list")) {
                return new Pair<TaskList, String>(tasksList, tasksList.toString());

            } else if (input.toLowerCase().startsWith("todo")) {
                return parseToDo(tasksList, input);
            } else if (input.toLowerCase().startsWith("deadline")) {
                return parseDeadline(tasksList, input);

            } else if (input.toLowerCase().startsWith("event")) {
                return parseEvent(tasksList, input);

            } else if (input.toLowerCase().startsWith("unmark")) {
                return parseUnmark(tasksList, input);

            } else if (input.toLowerCase().startsWith("mark")) {
                return parseMark(tasksList, input);

            } else if (input.toLowerCase().startsWith("delete")) {
                return parseDelete(tasksList, input);
                //task name can partially contain keyword
            } else if (input.toLowerCase().startsWith("find")) {
                return parseFind(tasksList, input);

            } else {
                output += ("Try entering a valid instruction! Eg. 'Todo Chores' or 'Mark 2'\n");
            }

        } else {
            output = "Bye! Hope to see you again soon!";
            System.out.println("Bye parsed");
            System.out.println(tasksList.toString());
            Storage storage = new Storage(tasksList);
            try {
                storage.store();
            } catch (IOException e) {
                System.err.println("Error writing to the file: " + e.getMessage());
                e.printStackTrace();
            }
        }

        return new Pair<TaskList, String>(tasksList, output);
    }

Example from src/main/java/duke/Storage.java lines 32-92:

    public void store() throws IOException{
        System.out.println("Ran storage");
        String filePathOld = "./data/toothless.txt";
        File oldFile = new File(filePathOld);
        String filePathNew = "./data/toothless.txt";
        File newFile = new File(filePathOld);
        try {
            Path filePath = Paths.get(filePathOld);

            Files.createDirectories(filePath.getParent());

            if (!Files.exists(filePath)) {
                Files.createFile(filePath);
            }
        } catch (IOException e) {
            System.out.println("Error" + e.getMessage());
        }
        FileWriter fw = new FileWriter(filePathOld);
        for (Task t : taskList.getTasksList()) {
            System.out.println("Stored successfully");
            String textToAdd = "";
            String taskType = t.getTaskType();
            if (taskType.equals("T")) {
                String name = t.getTaskName();
                String isDone = "0";
                if (t.getIsDone()) {
                    isDone = "1";
                }
                textToAdd += (taskType + " | " + isDone + " | " + name + "\n");
                fw.write(textToAdd);
                //System.out.println("1");
            } else if (taskType.equals("D")) {
                String name = t.getTaskName();
                String deadline = DateTimeParser.dtToString(t.getDeadline());
                String isDone = "0";
                if (t.getIsDone()) {
                    isDone = "1";
                }
                textToAdd += (taskType + " | " + isDone + " | " + name + " | " + deadline + "\n");
                fw.write(textToAdd);
            } else if (taskType.equals("E")) {
                String name = t.getTaskName();
                String start = DateTimeParser.dtToString(t.getStart());
                String end = DateTimeParser.dtToString(t.getEnd());
                String isDone = "0";
                if (t.getIsDone()) {
                    isDone = "1";
                }
                textToAdd += (taskType + " | " + isDone + " | " + name + " | " + " from " + start + " to " + end + "\n");
                fw.write(textToAdd);
            }
        }
        //System.out.println("1");
        fw.close();
        /*
        Path source = Paths.get("data/temp.txt");
        Path destination = Paths.get("data/toothless.txt");
        //oldFile.delete();
        Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
        */
    }

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/Toothless.java lines 104-106:

    /**
     * print lines for formatting
     */

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

No easy-to-detect issues 👍

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