I think there are ways to pass by reference and by value, but I heard that some programming languages have a way of passing called shared passing.
It was the first time for me to hear the term, so I looked it up, but it seems that it isn't used much (or rather, there are other ways to say it), so it's shared, passed by reference, or just value. There was also an article that said passing or passing by reference.
Is there anything that is generally called shared delivery, such as specifications and references?
The site you read
If there is such a proper material, I would like to use the name according to it …
- There are programming languages that use the term "shared passing".
- As far as I know, the word "pass by value" is used more in Japanese.
- However , you should be careful about using the term "pass by reference" for the following reasons:
- The meaning is slightly different depending on the programming language.
- It is confusing what the word "reference" means.
- For this reason, I personally think it is safe to choose the appropriate wording according to the programming language.
How to say "shared delivery"
There are programming languages that write the phrase "call-by-sharing, pass-by-sharing" in their documentation and specifications. Let me give you two concrete examples.
CLU (quoted from CLU Reference Manual, PDF )
Argument passing is defined in terms of assignment, the formal arguments of a routine are considered to be local variables of the routine and are initialized, by assignment, to the objects resulting from the evaluation of the argument expressions. We call the argument passing technique call by sharing , because the argument objects are shared between the caller and the called routine.
Julia (quoted from the manual )
Julia function arguments follow a convention sometimes called "pass-by-sharing", which means that values are not copied when they are passed to functions.
However, I don't think it is a very widely used word. For example, the English Wikipedia "Evaluation strategy" says:
However, the term "call by sharing" is not in common use; the terminology is inconsistent across different sources.
How to say "pass by reference"
In addition to the languages listed above, there are programming languages that have a passing method equivalent to "shared passing".
In this case, it is sometimes called "passing by reference" in the sense of a special case of passing by value, and Java examples often hit the search in Japanese blog articles ( example ). In the case of Java, the position is that all evaluation strategies are passed by value . When passing a reference value on this, it is sometimes called "passing by value of reference" in the sense of "passing by value of reference value". I often say "pass by value" rather than "pass by share", and I get the impression that the word "pass by value" is used especially in Japanese1.
However, in general, the term "pass by reference" should be used with caution. One reason is that the word "reference" is awkward and has slightly different meanings depending on the programming language.
In Java, a "reference" or "reference value" is a pointer to an object or a null pointer. Quoted from the Java SE 12 specification JSR 386 :
An object is a class instance or an array.
The reference values (often just references) are pointers to these objects, and a
special null reference, which refers to no object.
In C ++ 98, a " reference " is an alias for an existing object or function. In particular, it is different from pointers. C ++ 11 also adds the concept of rvalue reference.
- In OCaml, a "reference" is a ref-type value, that is, a mutable indirect reference cell.
For this reason, the specific behavior of "passing a reference by value" changes.
Another reason is that "passing by reference" is different from "passing by reference", but the text is similar and confusing2 . The execution results of the following programs differ between the two.
# Python っぽい疑似コードです。 def f(a): a =  l =  f(l) print(l) # ここで何が出力されるでしょうか。
Conclusion: How to use words
For the above reasons, I personally think as follows.
- Be careful as it may not be possible to communicate with "shared delivery".
- The phrase "pass by value for reference" is easily misunderstood for multiple reasons, so use it with caution.
- It seems easier to understand if you simply say "pass by value" after organizing how data is managed according to each programming language.
Especially regarding the last point, in languages such as Java and Python, the specification for function application only describes passing by value, and separately describes how data such as objects are treated as values. I am. Personally, I feel that it is easier to understand if you think separately and use terms in this way.
- I searched for the first appearance of the word "pass by reference", but I wasn't sure. If anyone knows, please comment.
- It becomes even more complicated if "pass by reference" and "pass by reference" coexist. For example, C # is a good example. There are value types and reference types in C # types, and you can choose to pass by value or by reference. Therefore, in C #, there can be "pass by value of value type", "pass by reference of value type", "pass by value of reference type", and "pass by reference of reference type". Note that "reference type" and "pass by reference" are different concepts. For details, refer to "Pass by reference" (++ C ++; // Unidentified flight C). By the way, I didn't write it in the text because it complicates the story, but C # has separate "reference type" and "reference to variable ( ref local )" as "reference" concepts, in addition. The language design allows you to pass by reference.