Question

I was training a new developer the other day and realized I don't know the actual term for "catching" a return value in a variable. For example, consider this pseudocoded method:

String updateString(newPart) {
  string += newPart;
  return string;
}

Assume this is being called to simply update the string - the return value is not needed:

updateString("add this");

Now, assume we want to do something with the returned value. We want to change the call so that we can use the newly updated string. I found myself saying "catch the return value", meaning I wanted to see:

String returnedString = updateString("add this");

So, if you were trying to ask someone to make this change, what terminology would you use? Is it different in different languages (since technically, you may be calling either a function or a method, depending on the language)?

Was it helpful?

Solution

assign the return value to a variable?

OTHER TIPS

Returned values can be assigned or discarded/ignored/not used/[insert synonym here].

There isn't really a technical term for it.

I would say "returnedString is to be initialised with the return value of updateString".

"Catch" makes me think of exceptions, which is a bit misleading. How about something like "use" or "store" or "assign"?

Common ones that I know:

  • You assign a value to a variable.
  • You store a value into a variable.

check the function's return value, do not ignore return values

In the example, you're simply assigning the return value of the function to a new variable.

When describing the behavior of that single line of code, it doesn't really matter that the return value is not essential to the use of the function. However, in a broader context, it is very important to know what purpose this "Interesting Return Value" serves.

As others have said there isn't really a word for what you describe. However, here's a bit of terminology for you to chew on: the example you give looks like it could be a Fluent Interface.

I suggest "cache", meaning store it for later. Maybe there's a subliminal reason you're saying "catch".

It's better too state the purpose rather than the implementation details (because actual implementation can be different in different programming langugages).

Generally speaking: - Save the return value of the call.

If you know the return value is a result of something: - Save the result of the call.

If you know the return value is to signify a status (such as error): - Save the status of the call.

By using the word "save", you can use that same statement across the board, regardless of the mechanism used in that particular language to save the return value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top