What does the term "catch" of the return value mean?

The other day I trained a new developer and realized that I did not know the actual term "catch" the return value in a variable. For example, consider this pseudo-encoded method:

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

Suppose this is called to just update a row - no return value is required:

 updateString("add this"); 

Now suppose we want to do something with the return value. We want to change the call so that we can use the updated string. I found that I say "catch the return value", that is, I want to see:

 String returnedString = updateString("add this"); 

So, if you were trying to ask someone to make this change, what terminology would you use? Does this differ in different languages ​​(from a technical point of view, you can call a function or method depending on the language)?

+4
source share
10 answers

Assign the return value to a variable?

+15
source

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

There is no technical term for this.

+5
source

I would say that "returnString must be initialized with the return value of updateString".

+3
source

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

+3
source

General I know:

  • You assign a value to a variable.
  • You save the value in a variable.
+3
source

check function return value, do not ignore return values

+2
source

In this example, you simply assign the return value of the function to a new variable.

When describing the behavior of this single line of code, it really doesn't matter that the return value is not essential for using the function. However, in a broader context, it is very important to know what this “interesting return value” is.

+2
source

As others have said, in fact there is not a word about what you are describing. However, there is a bit of terminology so you can chew: the example you give looks like this: Fluent Interface .

0
source

I suggest "cache", that is, store it later. Maybe there is a subconscious reason why you say catch.

0
source

It is also better to indicate the purpose and not the implementation details (because the actual implementation may be different in different programmable errors).

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

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

If you know that the return value means status (for example, an error): - Save the call status.

Using the word save, you can use the same operator in all directions, regardless of the mechanism used in that particular language, to save the return value.

-1
source

All Articles