Lasagna Master - add an explanation for the purpose of the return statement

On the Lasagna Master exercise, return statements are explained but there isn’t really any explanation for the purpose of them.

My suggestion would be to add an explanation below the first paragraph/code block of the “Return Statement” section, something like “The return value of a function can be stored in a variable for further use”.

It could be argued that the statement “A return statement ends the function execution and specifies a value to be returned to the function caller” in the first paragraph does explain its purpose, but I don’t think it would be clear enough for someone who is still learning about it that you can store the value in a variable, so I think at the very least that a concrete example of storing the returned value would be beneficial.

I can also make a PR for that.

Thanks!

In Exercism, we assume people already know the basics of programming before coming into Exercism. Then, the job of Exercism is showing how the concepts about programming you already know work in a particular language.

Reading that section, I get the sense it’s just trying to do just that - showing how return works in Javascript, not trying to explain the concept of returning itself. I feel that trying to explain the purpose of returning values to the caller might enter that area of trying to explain the concept of returning itself.

I’d argue that if someone doesn’t know why returning can be useful, it’s probably a sign they don’t know about programming enough to use Exercism, at least just yet.

I don’t think your suggestion is bad, and probably doesn’t hurt to add a simple explanation on how returning can be useful. But if that explanation it’s actually useful to someone, what other things about basic programming should we also must explain to that person? And again, Exercism is not a place to explain the basics of programming, just how the basics work on a particular language.

With that said, I’m not a Javascript maintainer, so take my opinion with a pinch of salt.

1 Like

I see, thanks for clarifying. I didn’t know that Exercism isn’t intended for absolute programming beginners.

2 Likes

I agree with your overall assessment.

@JorensM we’ll take a PR (link this topic). The reason adding this is fine is because there are programming languages without return or ret statements! So explaining it is fine.

Alright, cool, I’ll make a PR tomorrow if I have time!

Should it go in the Hello World exercise as well, even though that is more orientation? We also get quite a few “Can’t solve Hello World” messages, so it might help to have this information n the first exercise.

I think in that one students don’t have to write return themselves, so we don’t need to add it there!

No, that is for sure, but we could state “notice that this is not printing the result, but returning the value” or something to bring attention to that early on, as the others do not change. If they go to the next exercise, and did not note it in the “orientation” then we did not orient them well enough, likely.

Hello, here is the PR: Update Lasagna Master Introduction by JorensM · Pull Request #2517 · exercism/javascript · GitHub

1 Like

Does your added paragraph and example code accomplish what your complaint indicates?

Does this explain the purpose of them?

I think so, yes. Do you think it doesn’t? What would you suggest instead?

The return value of a function can be stored in a variable.

function sum(x, y) {
  return x + y;
}

const total = sum(5, 10);
// => 15

This is the paragraph that was added, and while the constant total is assigned the value of the return, for someone that does not recognize this, is it clear? Or does it matter than it is the return, specifically? What else would it be? And if we think of it as the “evaluation function sum” do we have to focus on the “return of the function” to understand what is happening here.

In other words, if there was some other thing happening in the function, that is not the return, then perhaps it would be clearer, in some ways, that we are not assigning the function itself, but its return, since there are other things going on there.

I think what I am trying to say is that this paragraph does not highlight what it is I think you are trying to bring out, as much as it could, since the work being done is pretty intuitive, and uninteresting (meaning that there is nothing that says “What? Oh, that is what is happening.”).

I think this can be solved by adding an example WITHOUT the return statement, and then total being undefined.

What do you think @JorensM ?

I agree, I think it’s a good idea and will highlight the default return behavior of a function. Though it seems that the ‘returning undefined’ paragraph has already been added in another PR

1 Like

I think and example preceding the one you added with undefined as return value is clear enough without having to duplicate the section about “implicitly returning undefined”.