Skip to content

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

Description

@soc-se-script

@wj200 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/mars/task/TaskList.java lines 60-61:

            }
            else {

Example from src/main/java/mars/task/TaskList.java lines 162-163:

            }
            else {

Example from src/main/java/mars/command/addCommand.java lines 38-39:

                }
                else {

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

Aspect: Package Name Style

No easy-to-detect issues 👍

Aspect: Class Name Style

Example from src/main/java/mars/marsException.java lines 3-3:

public class marsException extends RuntimeException{

Example from src/main/java/mars/command/echoCommand.java lines 7-7:

public class echoCommand extends Command{

Example from src/main/java/mars/command/byeCommand.java lines 10-10:

public class byeCommand extends Command {

Suggestion: Follow the class naming convention specified by the coding standard.

Aspect: Dead Code

No easy-to-detect issues 👍

Aspect: Method Length

Example from src/main/java/mars/task/TaskList.java lines 31-77:

    public TaskList(ArrayList<String> tasks) {
        this.tasks = new ArrayList<>();
        try{
        for (String line : tasks) {
            String desc;
            boolean isDone = (line.charAt(4) == 'X');
            if (line.charAt(1) == 'T') {
                /* unmarked task should follow format: [T][ ] run with an empty
                space in between second box so that line.substring() can be standardised to index 7 */
                desc = line.substring(7);
                this.add(new Todo(desc, isDone));
            } else if (line.charAt(1) == 'D') {
                String remaining_line = line.substring(7);
                String[] split_line = remaining_line.split(" \\(by: ");
                String name = split_line[0];
                String endDate = split_line[1].split("\\)")[0];
                String formattedEndDate = LocalDateTime.parse(endDate, MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                desc= name + " by " + formattedEndDate;
                this.add(new Deadline(desc, isDone));
            }
            else if (line.charAt(1) == 'D' &&  line.charAt(2) == 'W') {
                String remaining_line = line.substring(8);
                String[] split_line = remaining_line.split(" between: ");
                String name = split_line[0];
                String[] dates = split_line[1].split(" and: ");
                String formattedStartDate = LocalDateTime.parse(dates[0], MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                String formattedEndDate = LocalDateTime.parse(dates[1], MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                desc = name + " between: " + formattedStartDate + " and " + formattedEndDate;
                this.add(new DoWithin(desc, isDone));
            }
            else {
                String remaining_line = line.substring(7);
                String[] split_line = remaining_line.split(" \\(from: ");
                String name = split_line[0];
                String[] dates = split_line[1].split(" to: ");
                String startDate = dates[0];
                String formattedStartDate = LocalDateTime.parse(startDate, MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                String endDate = dates[1].split("\\)")[0];
                String formattedEndDate = LocalDateTime.parse(endDate, MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                desc = name + " from " + formattedStartDate + " to " + formattedEndDate;
                this.add(new Event(desc, isDone));
            }
        }
        } catch (PatternSyntaxException e) {
           System.out.println("PatternSyntaxException: " + e.getMessage());
        }
    }

Example from src/main/java/mars/command/addCommand.java lines 28-109:

    public void execute(TaskList tasklist, UI ui, Storage storage) throws marsException{
        String taskType = this.taskType;
        String details = this.details;
        String[] parts;
        String message = "";
        switch(taskType){
            case "todo":
                parts = details.split(" ", 2);
                if (parts[1].isEmpty()){
                    throw new marsException("OOPS!!! The description of a " + taskType + " cannot be empty\n ");
                }
                else {
                    Todo todo =  new Todo(parts[1], false);
                    tasklist.add(todo);
                    message = "Got it. I've added this task: \n" + todo;
                }
                break;
            case "deadline":
                parts = details.split("\\(by: ", 2);
                if (parts[1].isEmpty()){
                    throw new marsException("Invalid or empty description of a " + taskType + "\n");
                }
                else {
                    String endDate = parts[1].split("\\)", 2)[0];
                    String formattedEndDate = LocalDateTime.parse(endDate, MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                    String deadlineDesc = parts[0] + " by " + formattedEndDate;
                    Deadline deadline = new Deadline(deadlineDesc, false);
                    tasklist.add(deadline);
                    message = "Got it. I've added this task: \n" + deadline;
                }
                break;
            case "event" :
                parts = details.split(" ", 2);
                if (parts[1].isEmpty()){
                    throw new marsException("OOPS!!! The description of a " + taskType + " cannot be empty\n " + HORIZONTAL_LINE);
                }
                else {
                    String[] desc = parts[1].split("\\(from: ", 2);
                    String event = desc[0];
                    String[] dates = desc[1].split(" to: ", 2);
                    String startDate = dates[0];
                    String endDate = dates[1].split("\\)")[0];

                    if (startDate.isEmpty() || endDate.isEmpty()){
                        throw new marsException("Invalid or empty description of a " + taskType + "\n");
                    }
                    else {
                        String formattedStartDate = LocalDateTime.parse(startDate, MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                        String formattedEndDate = LocalDateTime.parse(endDate, MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                        String eventDesc = event + "from: " + formattedStartDate + " to: " + formattedEndDate;
                        Event eventTask = new Event(eventDesc, false);
                        tasklist.add(eventTask);
                        message = "Got it. I've added this task: \n" + eventTask;
                    }
                }
                break;
            case "do within":
                 String[] firstPart = details.split(" ", 2);
                 parts = firstPart[1].split(" ", 2);
                 String[] desc = parts[1].split("between: ", 2);
                 String event = desc[0];
                 String[] dates = desc[1].split(" and ", 2);
                 String formattedStartDate = LocalDateTime.parse(dates[0], MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                 String formattedEndDate = LocalDateTime.parse(dates[1], MONTH_DAY_YEAR).format(YEAR_MONTH_DAY);
                 String eventDesc = event + " between: " + formattedStartDate + " and " + formattedEndDate;
                 DoWithin doWithinTask = new DoWithin(eventDesc, false);
                 tasklist.add(doWithinTask);
                 message = "Got it. I've added this task: \n" + doWithinTask ;
                 break;
            default: throw new marsException("OOPS!!! I'm sorry, but I don't know what that means :-(\n");
        }

        if(tasklist.size() == 1){
            message += "\nNow you have 1 task in the list.\n";
            ui.setResponse(message);
        }
        else{
            message += "\nNow you have " + tasklist.size() + " tasks in the list.\n";
            ui.setResponse(message);
        }

    }

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 Messages

possible problems in commit 123ca39:


Moved Ui.png to root


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


❗ 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