Skip to content

Sharing iP code quality feedback [for @superb-sushi] - Round 2 #10

@soc-se-bot-red

Description

@soc-se-bot-red

@superb-sushi 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/blob/Parser.java lines 93-135:

    public String executeDeadline(TaskList tasklist, String[] arr) {
        int i = 0;
        int by = 0;
        for (int j = 0; j < arr.length; j++) {
            if (arr[j].equals("/by")) {
                by = j;
            }
        }
        // task name error handling
        if (by <= 1) {
            return "I require a description for your 'deadline' task 😅!";
        }
        // task deadline error handling
        if (by == arr.length - 1) {
            return "Your deadline task can't not have a deadline! Please enter your task again!";
        }
        //task deadline only having date or time
        if (by == arr.length - 2) {
            return "You need to add both DATE and TIME to your deadline \uD83D\uDD27! (Format: yyyy-mm-dd HH:mm)";
        }
        StringBuilder msg = new StringBuilder("");
        // for task name string
        StringBuilder a = new StringBuilder(arr[i + 1]);
        for (int l = i + 2; l < by; l++) {
            System.out.println("word:-" + arr[l] + "-");
            StringBuilder str = new StringBuilder(" " + arr[l]);
            a = a.append(str);
        }
        // for task deadline string
        StringBuilder stringDate = new StringBuilder(arr[by + 1]);
        StringBuilder stringTime = new StringBuilder(arr[by + 2]);
        String Iso8601Format = stringDate.toString() + "T" + stringTime.toString() + ":00";
        try {
            Deadline d = new Deadline(a.toString(), false, Iso8601Format, new ArrayList<String>());
            tasklist.addTask(d);
            msg.append("Got it. I've added this task:\n");
            msg.append(d + "\n");
            msg.append("Now you have " + tasklist.getSize() + " tasks in the list.");
        } catch (DateTimeParseException e) {
            msg.append("Input dates and times not in the format 'yyyy-mm-dd HH:mm'!");
        }
        return msg.toString();
    }

Example from src/main/java/blob/Parser.java lines 137-198:

    public String executeEvent(TaskList tasklist, String[] arr) {
        int i = 0;
        int start = 0;
        int end = 0;
        for (int j = 0; j < arr.length; j++) {
            if (arr[j].equals("/from")) {
                start = j;
            } else if (arr[j].equals("/to")) {
                end = j;
            }
        }
        // task name error handling
        if (start <= 1) {
            return "What's the name of your event? Please add it 😅!";
        }
        // start string error handling
        if (end - start <= 1) {
            return "When does your event begin? Please add it 😅!";
        }
        // end string error handling
        if (end == arr.length - 1) {
            return "What time does your event end? Please let me know 😅!";
        }
        //'/from' only having date or time
        if (end - start == 2) {
            return "You need to add both DATE and TIME to your event's start \uD83D\uDD27! (Format: yyyy-mm-dd HH:mm)";
        }
        //'/to' only having date or time
        if (end == arr.length - 2) {
            return "You need to add both DATE and TIME to your event's end \uD83D\uDD27! (Format: yyyy-mm-dd HH:mm)";
        }

        StringBuilder msg = new StringBuilder("");

        //for task name string
        StringBuilder a = new StringBuilder(arr[i + 1]);
        for (int l = i + 2; l < start; l++) {
            StringBuilder str = new StringBuilder(" " + arr[l]);
            a = a.append(str);
        }

        //for start string
        StringBuilder startDate = new StringBuilder(arr[start + 1]);
        StringBuilder startTime = new StringBuilder(arr[start + 2]);
        String startIso8601Format = startDate.toString() + "T" + startTime.toString() + ":00";

        //for end string
        StringBuilder endDate = new StringBuilder(arr[end + 1]);
        StringBuilder endTime = new StringBuilder(arr[end + 2]);
        String endIso8601Format = endDate.toString() + "T" + endTime.toString() + ":00";

        try {
            Event e = new Event(a.toString(), false, startIso8601Format, endIso8601Format, new ArrayList<String>());
            tasklist.addTask(e);
            msg.append("Got it. I've added this task:\n");
            msg.append(e + "\n");
            msg.append("Now you have " + tasklist.getSize() + " tasks in the list.");
        } catch (DateTimeParseException e) {
            msg.append("Input dates and times not in the format 'yyyy-mm-dd HH:mm'!");
        }
        return msg.toString();
    }

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

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