nus-cs2103-AY1819S2 / forum

CS2103/T discussion forum
6 stars 1 forks source link

Question on sequence diagram with multiple return statements #94

Open limli opened 5 years ago

limli commented 5 years ago

image

This is from sem 1's pyp. My question is, how do you represent a return statement inside of a if statement using sequence diagram? I believe "alt"s are used for if statements, but the return makes it a bit awkward.

image

daviddl9 commented 5 years ago

My guess would be that it looks something likes this: image

limli commented 5 years ago

I see. Thank you :)

daviddl9 commented 5 years ago

@limli I'm not 100% sure though pls wait for profs reply

lingyanhao commented 5 years ago

@daviddl9 I don't agree with your answer. Your sequence diagram suggests that the return statement occurs outside the if-else block.

So the code corresponding it would look something like Task generate(boolean hasExisting) { Task t; if (hasExisting) { t = getTask(); } else { t = new Task(); } return t; } (Sorry for poor indentation, I don't know how to use proper indentation in markdown)

fterh commented 5 years ago

I agree with @lingyanhao and I feel @limli 's diagram is more representative of the original algorithm...

ccristina commented 5 years ago

Hi,

Indeed @limli's diagram is representative, while @daviddl9's diagram is incorrect when representing the return statements.

@limli's diagram: the return arrows need to be longer, and end outside the alt box.

Best regards, Cristina

daviddl9 commented 5 years ago

Okie thanks for the correction!