Skip to content

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

@soc-se-bot

Description

@soc-se-bot

@shadhankkk 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/duke/Duke.java lines 49-202:

    public String getResponse(String input) {
        parser.readInput(input);
        String response = "";

        String command = parser.getArgument(' ');
        taskList = loader.load();
        if(command.equals(exitCommand)) {

            ui.printClosing();
            response = "bye!";
            System.exit(0);

        } else if(command.equals("list")) {

            response = taskList.listTasks();

        } else if(command.equals("mark")) {

            int rankToMark = Integer.valueOf(parser.getArgument('\n'));

            response = taskList.markTask(rankToMark);
        } else if(command.equals("unmark")) {

            int rankToUnmark = Integer.valueOf(parser.getArgument('\n'));

            response = taskList.unmarkTask(rankToUnmark);
        } else if(command.equals("todo")) {
            assert input.length() > 5;

            if(input.length() == 4) {
                ui.printError("Error: The description of a todo cannot be empty. Terminating program.");
                response = "Error: The description of a todo cannot be empty.";
            }

            String taskName = parser.getArgument('\n');

            if(isEmptyString(taskName)) {
                ui.printError("Error: The description of a todo cannot be empty. Terminating program.");
                response = "Error: The description of a todo cannot be empty.";
            }

            taskName = taskName.trim();
            response = taskList.addTask(new Task(taskName, TODO));
        } else if(command.equals("deadline")) {
            assert input.length() > 9;


            if(input.length() <= 9) {
                ui.printError("Error: The description of a deadline cannot be empty. Terminating program.");
                response = "Error: The description of a deadline cannot be empty.";
            }

            String taskName = parser.getArgument('/', 4);

            if(isEmptyString(taskName)) {
                ui.printError("Error: The description of a deadline cannot be empty. Terminating program.");
                response = "Error: The description of a deadline cannot be empty.";
            }

            if(input.length() <= 9 + taskName.length() + 4) {
                ui.printError("Error: No deadline provided. Terminating program.");
                response = "Error: No deadline provided.";
            }

            String deadline = parser.getArgument('\n');
            deadline = deadline.trim();

            if(isEmptyString(deadline)) {
                ui.printError("Error: No deadline provided. Terminating program.");
                response = "Error: No deadline provided.";
            }

            taskName = taskName.trim();

            response = taskList.addTask(new Task(taskName, DEADLINE, deadline));

        } else if(command.equals("event")) {

            assert input.length() > 6;

            if(input.length() <= 5) {
                ui.printError("Error: The description of an event cannot be empty. Terminating program.");
                response = "Error: The description of an event cannot be empty.";
            }

            String taskName = parser.getArgument('/', 6);

            if(isEmptyString(taskName)) {
                ui.printError("Error: The description of an event cannot be empty. Terminating program.");
                response = "Error: The description of an event cannot be empty.";
            }

            if(input.length() <= 6 + taskName.length() + 6) {
                ui.printError("Error: No start time provided for event. Terminating program.");
                response = "Error: No start time provided for event.";
            }

            String startTime = parser.getArgument('/', 4);

            if(isEmptyString(startTime)) {
                ui.printError("Error: No start time provided for event. Terminating program.");
                response = "Error: No start time provided for event.";
            }

            if(input.length() <= 6 + taskName.length() + 6 + startTime.length() + 4) {
                ui.printError("Error: No end time provided for event. Terminating program.");
                response = "Error: No end time provided for event.";
            }

            String endTime = parser.getArgument('\n');
            endTime = endTime.trim();

            if(isEmptyString(endTime)) {
                ui.printError("Error: No end time provided for event. Terminating program.");
                response = "Error: No end time provided for event.";
            }

            taskName = taskName.trim();
            startTime = startTime.trim();

            String[] eventTimings = new String[] {startTime, endTime};


            response = taskList.addTask(new Task(taskName, EVENT, eventTimings));
        } else if(command.equals("delete")) {
            assert input.length() > 7;

            if(input.length() <= 7) {
                ui.printError("Error: You need to specify which task to delete. Terminating program.");
                response = "Error: You need to specify which task to delete.";
            }

            int rankToDelete = Integer.valueOf(parser.getArgument('\n'));

            response = taskList.deleteTask(rankToDelete);

        }  else if(command.equals("find")) {
            assert input.length() > 5;

            if(input.length() <= 5) {
                ui.printError("Error: You need to give a search query. Terminating program.");
                response = "Error: You need to give a search query.";
            }
            String query = parser.getArgument('\n');
            response = taskList.fetchQuery(query);
        }  else {

            System.out.println("Error: Invalid input, terminating program.");
            return "Error: Invalid input";
        }

        saver.save(taskList);
        return response;
    }

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

    public void save(TaskList taskList) {

        ArrayList<Task> tasks = taskList.tasks;
        try {
            File myObj = new File(filepath);
            myObj.createNewFile();

            FileWriter fw = new FileWriter(filepath);

            int tasksLen = tasks.size();

            for(int i=0; i<tasksLen; ++i) {
                Task task = tasks.get(i);
                String toWrite = "";
                if (task.type == TODO) {
                    toWrite += "T|";
                } else if (task.type == DEADLINE) {
                    toWrite += "D|";
                } else if (task.type == EVENT) {
                    toWrite += "E|";
                }

                if(task.isMarked) {
                    toWrite += "1|";
                } else {
                    toWrite += "0|";
                }

                toWrite += task.name;
                toWrite += "|";

                if(task.type == TODO) {
                    toWrite += "||";
                }

                if(task.type == DEADLINE) {
                    toWrite += task.deadline + "||";
                }

                if(task.type == EVENT) {
                    toWrite += task.eventTimings[0] + "|" + task.eventTimings[1] + "|";
                }

                toWrite += '\n';

                fw.write(toWrite);
            }

            fw.close();

        } catch (IOException e) {

            System.out.println("An error occurred.");
            e.printStackTrace();

        };
    }

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

    public TaskList load() {
        TaskList taskList = new TaskList(ui);

        try {
            File myObj = new File(filepath);
            myObj.createNewFile();

            FileReader fr = new FileReader(filepath);

            BufferedReader br = new BufferedReader(fr);

            String strLine;

            while((strLine = br.readLine()) != null) {
                int ptr = 0;
                int len = strLine.length();
                String taskType = "" + strLine.charAt(ptr);
                ptr += 2;
                String isMarked = "" + strLine.charAt(ptr);
                ptr += 2;
                String taskDescription = getCommand(strLine, ptr, '|');
                ptr += taskDescription.length() + 1;
                String deadline1 = getCommand(strLine, ptr, '|');
                ptr += deadline1.length() + 1;
                String deadline2 = getCommand(strLine, ptr, '|');
                ptr += deadline2.length() + 1;

                Task task;

                if(taskType.equals("T")) {
                    task = new Task(taskDescription, TODO);
                } else if (taskType.equals("D")) {
                    task = new Task(taskDescription, DEADLINE, deadline1);
                } else {
                    String[] eventTimings = new String[] {deadline1, deadline2};
                    task = new Task(taskDescription, EVENT, eventTimings);
                }

                if(isMarked.equals("1")) {
                    task.mark();
                }

                taskList.addTaskWithoutPrinting(task);
            }

        } catch (IOException e) {

            System.out.println("An error occurred.");
            e.printStackTrace();

        };

        return taskList;
    }

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


v0.6


  • Perhaps too short (?)

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

Suggestion: Avoid committing binary files (e.g., *.class, *.jar, *.exe) or third-party library files in to the repo.


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

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