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

[Lyu Xingyu] iP #206

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

[Lyu Xingyu] iP #206

wants to merge 30 commits into from

Conversation

Zemdalk
Copy link

@Zemdalk Zemdalk commented Feb 1, 2023

No description provided.

Comment on lines 32 to 36
if(line.equals("bye")){
// quit
System.out.println(exitPrompt);
break;
}else{

Choose a reason for hiding this comment

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

Perhaps you can leave a space after the conditional clause and opening brace

Comment on lines 66 to 70
try {
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1;
} catch (Exception e) {
index = -1;
}

Choose a reason for hiding this comment

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

I like how you have added error handling

Choose a reason for hiding this comment

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

New implementation I've noticed. I have not seen this before. Maybe something that I should google up. Well done~

if(funcIdx == -1){
funcIdx = line.length();
}
String func = line.substring(0, funcIdx);

Choose a reason for hiding this comment

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

perhaps you could give this variable a better name, as it is stored as a String but is named func

Choose a reason for hiding this comment

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

I agree with @lihka1202 . I'd suggest to give a variable name like commandIndex or inputIndex as it it a bit more clear for readers to understand what you are referring to.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your good suggestions! I have made corrections.

}
todoList.markItem(index, false);
}else if(func.equals("todo")){
Todo todo = Todo.toTodo(instruction);

Choose a reason for hiding this comment

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

Perhaps you could name object todo better, as it has the same name as the class and it might get confusing!

// mark work as done
int index;
try {
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1;

Choose a reason for hiding this comment

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

Could you abstract this out to maintain SLAP

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. Thank you for your suggestion!

if(funcIdx == -1){
funcIdx = line.length();
}
String func = line.substring(0, funcIdx);

Choose a reason for hiding this comment

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

I agree with @lihka1202 . I'd suggest to give a variable name like commandIndex or inputIndex as it it a bit more clear for readers to understand what you are referring to.

Comment on lines 66 to 70
try {
index = Integer.parseInt(line.substring(funcIdx+1, line.length())) - 1;
} catch (Exception e) {
index = -1;
}

Choose a reason for hiding this comment

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

New implementation I've noticed. I have not seen this before. Maybe something that I should google up. Well done~

Comment on lines 7 to 8
int contentIdx = instruction.indexOf("/from");
int fromIdx = instruction.indexOf("/to");

Choose a reason for hiding this comment

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

Perhaps u could use Index instead of Idx

Comment on lines 71 to 89
if(todo == null){
printError("Wrong todo format");
continue;
}
todoList.addItem(todo);
}else if(func.equals("deadline")){
Deadline deadline = Deadline.toDeadline(instruction);
if(deadline == null){
printError("Wrong deadline format");
continue;
}
todoList.addItem(deadline);
}else if(func.equals("event")){
Event event = Event.toEvent(instruction);
if(event == null){
printError("Wrong event format");
continue;
}
todoList.addItem(Event.toEvent(instruction));
Copy link

Choose a reason for hiding this comment

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

'switch' statement would be better since there are many cases you want to separate.

Copy link

@0nandon 0nandon left a comment

Choose a reason for hiding this comment

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

Function is better to be in verb form.

return new Deadline(deadlineContent, deadlineBy);
}

public Deadline(String description, String by) {
Copy link

Choose a reason for hiding this comment

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

Suggested change
public Deadline(String description, String by) {
public getDeadline(String description, String by) {

Copy link

@0nandon 0nandon left a comment

Choose a reason for hiding this comment

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

It is better to avoid deep nesting as possible as you can.

Comment on lines 71 to 89
if(todo == null){
printError("Wrong todo format");
continue;
}
todoList.addItem(todo);
}else if(func.equals("deadline")){
Deadline deadline = Deadline.toDeadline(instruction);
if(deadline == null){
printError("Wrong deadline format");
continue;
}
todoList.addItem(deadline);
}else if(func.equals("event")){
Event event = Event.toEvent(instruction);
if(event == null){
printError("Wrong event format");
continue;
}
todoList.addItem(Event.toEvent(instruction));
Copy link

Choose a reason for hiding this comment

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

There is deep nesting in if-else statement while every if statements inside are conducting similar calculation. There would be other way to better construct this code like declaring special function for those calculation.

Comment on lines 40 to 46
System.out.println(SPLITTER);
System.out.println(" OK, I've marked this task as not done yet:");
System.out.print(" [ ] ");
}
System.out.println(tasks[num].getDescription());
System.out.println(SPLITTER);
System.out.println();
Copy link

@0nandon 0nandon Feb 3, 2023

Choose a reason for hiding this comment

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

So many printings, I think in if-else statement. How about just making additional function for those printing stacks?

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.

4 participants