-
Notifications
You must be signed in to change notification settings - Fork 0
Sharing iP code quality feedback [for @leroychiu20] #3
Description
@leroychiu20 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
Example from src/main/java/AlexExceptions.java lines 6-6:
//super(message);Example from src/main/java/alex/task/Event.java lines 12-12:
//public LocalDate dueDate;Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/alex/Alex.java lines 36-77:
public String handleCommand(String userInput) {
if (userInput.equalsIgnoreCase("bye")) {
return ui.byeMessage();
} else if (userInput.equalsIgnoreCase("list")) {
return tasks.handleList();
} else if (userInput.startsWith("mark")) {
String tmp = tasks.handleMark(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else if (userInput.startsWith("unmark")) {
String tmp = tasks.handleUnmark(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else if (userInput.startsWith("todo")) {
String tmp = tasks.handleTodo(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else if (userInput.startsWith("deadline")) {
String tmp = tasks.handleDeadline(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else if (userInput.startsWith("event")) {
String tmp = tasks.handleEvent(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else if (userInput.startsWith("delete")) {
String tmp = tasks.handleDelete(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else if (userInput.startsWith("tasks on")) {
return tasks.handleDate(userInput);
} else if (userInput.startsWith("find")) {
return tasks.handleFind(userInput);
} else if (userInput.startsWith("tag")) {
String tmp = tasks.handleTag(userInput);
storage.saveTasksToFile(filePath);
return tmp;
} else {
return "Sorry, I don't understand that command. Did you make a typo?";
}
}Example from src/main/java/alex/storage/Storage.java lines 48-87:
public ArrayList<Task> loadTasksFromFile(String file) {
ArrayList<Task> list = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String desc;
while ((desc = reader.readLine()) != null) {
Task task;
if (desc.startsWith("[T]")) {
String details = desc.substring(6).trim();
task = new Todo(details);
} else if (desc.startsWith("[D]")) {
String details = desc.substring(6);
String[] info = details.split("//");
String item = info[0].trim();
String dueInter = info[1].substring(4).trim();
LocalDate dueDate = LocalDate.parse(dueInter);
task = new Deadline(item, dueDate);
} else {
String details = desc.substring(6);
String[] info = details.split("//");
String item = info[0].trim();
String startInter = info[1].substring(6).trim();
LocalDate start = LocalDate.parse(startInter);
String dueInter = info[2].substring(4).trim();
LocalDate dueBy = LocalDate.parse(dueInter);
task = new Event(item, start, dueBy);
}
task.isDone = desc.substring(4,5).equals("X") ? true : false;
list.add(task);
}
} catch (IOException e) {
try {
File dataFile = new File(file);
dataFile.createNewFile();
} catch (IOException ee) {
System.err.println("Error reading tasks from file: " + ee.getMessage());
}
}
tasks = list;
return list;
}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 6c79080:
Improve code quality
To make the code more readable, code quality must be improved. This is to ensure that someone reading the code is able to understand what is going on at all times.
Let's edit any lines of code that has deep nesting to code without, avoid ambiguous terms, and add comments before each method or class to explain its purpose.
- body not wrapped at 72 characters: e.g.,
To make the code more readable, code quality must be improved. This is to ensure that someone reading the code is able to understand what is going on at all times.
possible problems in commit b98e43e:
Add assertion statements
I as a programmer may introduce bugs into my code.
Adding assertion statements will help me to know when I introduced unwanted bugs into my code while editing the code.
Assertion statements should be used, not catching exceptions, because exceptions are meant to indicate that the user or environment messed up.
- body not wrapped at 72 characters: e.g.,
Adding assertion statements will help me to know when I introduced unwanted bugs into my code while editing the code.
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.