Skip to content
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

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Conversation

deveshl
Copy link

@deveshl deveshl commented Aug 29, 2022

No description provided.

Copy link

@jorellesee jorellesee left a 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


Task task = tasks.get(taskIndex);
task.setDone(isDone);
System.out.println("Okay, dude, I've marked this task as " + (isDone ? "done" : "not done yet") + ": ");

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

"$$ | $$ |$$ | $$ |$$ | $$ |$$ ____|\n" +
"$$$$$$$ |\\$$$$$$ |\\$$$$$$$ |\\$$$$$$$\\ \n" +
"\\_______/ \\______/ \\_______| \\_______|";
static final String GREET = "I am Dude.\n" +

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!

"\\_______/ \\______/ \\_______| \\_______|";
static final String GREET = "I am Dude.\n" +
"Type something in, dude.";
static final String BYE = "Catch you later, dude.";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

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());

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.

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

Copy link

@alfred-leong alfred-leong left a 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!

tasks.add(task);
System.out.println("added: " + command);
break;
}

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!

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());

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

case "bye":
System.out.println(BYE);
System.exit(0);
// no break needed, the code has already exited

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 👍


public static void runCommand(String command) {
String[] args = command.split(" ");
switch (args[0]) {

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

Comment on lines 20 to 51
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;
}
}
}

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.


static List<Task> tasks = new ArrayList<>();

public static void runCommand(String command) {

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.

Comment on lines 6 to 16
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.";

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

Comment on lines 14 to 18
public void setDone(boolean isDone) {
this.isDone = isDone;
}

public boolean isDone() {

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.

Copy link

@okkhoy okkhoy left a 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.

} 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.");
Copy link

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.

Comment on lines 50 to 52
case "todo":
case "deadline":
case "event": {
Copy link

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

case "deadline":
case "event": {
if (args.length < 2) {
System.out.println("Not enough arguments, dude."); // repeated code, can this be collapsed?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrt comment:

  1. if yes, it should be. not left as is.
  2. 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

Comment on lines 70 to 73
case "todo": {
task = createTodo(taskData);
break;
}
Copy link

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

Copy link
Author

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

Comment on lines 102 to 105
if (!taskData.contains("/at")) {
System.out.println("Missing /at parameter");
return null;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better handled as exceptions

@@ -0,0 +1,27 @@
public class Task {
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants