-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Devesh Logendran] iP #63
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great work! But consider using lambdas in different lines instead to make the code more readable
src/main/java/Duke.java
Outdated
|
||
Task task = tasks.get(taskIndex); | ||
task.setDone(isDone); | ||
System.out.println("Okay, dude, I've marked this task as " + (isDone ? "done" : "not done yet") + ": "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the use of a lambda here makes the code slightly less readable
src/main/java/Duke.java
Outdated
"$$ | $$ |$$ | $$ |$$ | $$ |$$ ____|\n" + | ||
"$$$$$$$ |\\$$$$$$ |\\$$$$$$$ |\\$$$$$$$\\ \n" + | ||
"\\_______/ \\______/ \\_______| \\_______|"; | ||
static final String GREET = "I am Dude.\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the use of all caps here to tell the reader that this is a constant. Good job!
src/main/java/Duke.java
Outdated
"\\_______/ \\______/ \\_______| \\_______|"; | ||
static final String GREET = "I am Dude.\n" + | ||
"Type something in, dude."; | ||
static final String BYE = "Catch you later, dude."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here!
src/main/java/Duke.java
Outdated
case "list": | ||
for (int i = 0; i < tasks.size(); i++) { | ||
Task task = tasks.get(i); | ||
System.out.printf("%d.[%s] %s\n", i + 1, (task.isDone() ? "X" : " "), task.getDescription()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps more could be done to make this line more readable? Consider not using the lambda or putting it in a different line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it would be great to make this line more understandable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, maybe some minor changes to some variables and code to make it more readable would be aweomse!
src/main/java/Duke.java
Outdated
tasks.add(task); | ||
System.out.println("added: " + command); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey I like how clean and readable your code is!
src/main/java/Duke.java
Outdated
case "list": | ||
for (int i = 0; i < tasks.size(); i++) { | ||
Task task = tasks.get(i); | ||
System.out.printf("%d.[%s] %s\n", i + 1, (task.isDone() ? "X" : " "), task.getDescription()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it would be great to make this line more understandable
src/main/java/Duke.java
Outdated
case "bye": | ||
System.out.println(BYE); | ||
System.exit(0); | ||
// no break needed, the code has already exited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great comment to help the reader understand what happens after the exit command 👍
src/main/java/Duke.java
Outdated
|
||
public static void runCommand(String command) { | ||
String[] args = command.split(" "); | ||
switch (args[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to rename "args[0]" to a name that is easy for the reader to understand the variable
src/main/java/Duke.java
Outdated
public static void runCommand(String command) { | ||
String[] args = command.split(" "); | ||
switch (args[0]) { | ||
case "bye": | ||
System.out.println(BYE); | ||
System.exit(0); | ||
// no break needed, the code has already exited | ||
case "list": | ||
for (int i = 0; i < tasks.size(); i++) { | ||
Task task = tasks.get(i); | ||
System.out.printf("%d.[%s] %s\n", i + 1, (task.isDone() ? "X" : " "), task.getDescription()); | ||
} | ||
break; | ||
case "mark": | ||
case "unmark": { | ||
boolean isDone = args[0].equals("mark"); | ||
int taskIndex = Integer.parseInt(args[1]) - 1; // add code to handle oob, missing argument | ||
|
||
Task task = tasks.get(taskIndex); | ||
task.setDone(isDone); | ||
System.out.println("Okay, dude, I've marked this task as " + (isDone ? "done" : "not done yet") + ": "); | ||
System.out.println(task.getDescription()); | ||
break; | ||
} | ||
default: { | ||
Task task = new Task(command); | ||
tasks.add(task); | ||
System.out.println("added: " + command); | ||
break; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method runCommand is 31 lines long, excluding the ending curly braces it is still 29. A rather lengthy method and you can possibly improve code quality if you take corrective action.
src/main/java/Duke.java
Outdated
|
||
static List<Task> tasks = new ArrayList<>(); | ||
|
||
public static void runCommand(String command) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming of this method could be better, runCommand does not immediately explain the method to the reader accurately and at a sufficient level of detail.
src/main/java/Duke.java
Outdated
static final String LOGO = "$$$$$$$\\ $$\\ \n" + | ||
"$$ __$$\\ $$ | \n" + | ||
"$$ | $$ |$$\\ $$\\ $$$$$$$ | $$$$$$\\ \n" + | ||
"$$ | $$ |$$ | $$ |$$ __$$ |$$ __$$\\ \n" + | ||
"$$ | $$ |$$ | $$ |$$ / $$ |$$$$$$$$ |\n" + | ||
"$$ | $$ |$$ | $$ |$$ | $$ |$$ ____|\n" + | ||
"$$$$$$$ |\\$$$$$$ |\\$$$$$$$ |\\$$$$$$$\\ \n" + | ||
"\\_______/ \\______/ \\_______| \\_______|"; | ||
static final String GREET = "I am Dude.\n" + | ||
"Type something in, dude."; | ||
static final String BYE = "Catch you later, dude."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOGO is okay but GREET and BYE in your context are verbs and they are a constant variable so they should be named like nouns. For eg, GREETING and GOODBYE
src/main/java/Task.java
Outdated
public void setDone(boolean isDone) { | ||
this.isDone = isDone; | ||
} | ||
|
||
public boolean isDone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good appropriate naming for boolean methods and setter for boolean variable. Makes the code very readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is generally quite well written. However, I do notice that you haven't completed some of the more recent tasks. Please catch up on the iP activities soon; do let me know if you need any help with the topics.
src/main/java/Duke.java
Outdated
} catch (NumberFormatException e) { | ||
// user either didn't enter a number or number was too big for integer | ||
// not a nice way to use exceptions but alternatives are cumbersome | ||
System.out.println("Invalid argument, dude."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could explain what you have in the comment in the error message.
src/main/java/Duke.java
Outdated
case "todo": | ||
case "deadline": | ||
case "event": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to include explicit fallthrough comment
src/main/java/Duke.java
Outdated
case "deadline": | ||
case "event": { | ||
if (args.length < 2) { | ||
System.out.println("Not enough arguments, dude."); // repeated code, can this be collapsed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrt comment:
- if yes, it should be. not left as is.
- it is better to use comments like this one on Github to record such comments rather than include it in the code.
- Such comments can become stale very soon
src/main/java/Duke.java
Outdated
case "todo": { | ||
task = createTodo(taskData); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are no braces around case statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I were to declare a variable with the same name in two different cases, the braces are necessary to distinguish them as being as different scopes, or else Java complains about variable redefinition within the same scope. In this case I have fortuitously avoided that scenario, but this will probably come up as I add more code, and I'm not sure what the best way to handle this apart from putting braces around every case statement (using if statements instead? defining common variables in case statements just outside the switch statement?)
src/main/java/Duke.java
Outdated
if (!taskData.contains("/at")) { | ||
System.out.println("Missing /at parameter"); | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better handled as exceptions
src/main/java/Task.java
Outdated
@@ -0,0 +1,27 @@ | |||
public class Task { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All non-trivial classes and methods should have header comments
# Conflicts: # src/main/java/duke/Duke.java
No description provided.