Call-by-Reference vs Call-by-Value
Call-by-value: passing values around by using the copies of the value. Call-by-reference: passing values around by using a reference (also called pointer or handle) to the value.
In Java, only call-by-reference is used for non-primitive values and call-by-value for primitive values. In Smalltalk, everything is an object and everything is passed by reference. In C++, you can do it either way. Remember why you want to control your copy constructor? Because your values may be copied onto the stack if they are passed by value.
Now this post is not intended to be a discussion on this language feature. Rather, this is also a user model. When we send a document as an attachment in an email, we are passing it around by value. Problem is, this value may be modified by multiple users and the modified copies can come back to you for you to consolidate, which close to impossible to do. Call-by-value is a very bad user model. When you send a link to a web resource in an email, you are passing it around by reference. Everybody then goes to the same place to access it. This elimiates many problems. Call-by-reference is the correct user model in most cases. Of course, when the user is offline, you have to use some type of call-by-value. Modern email servers support this mode when you check download message to local so that you can access your emails when you are offline.
So, CBR for online and CBV for offline.
In Java, only call-by-reference is used for non-primitive values and call-by-value for primitive values. In Smalltalk, everything is an object and everything is passed by reference. In C++, you can do it either way. Remember why you want to control your copy constructor? Because your values may be copied onto the stack if they are passed by value.
Now this post is not intended to be a discussion on this language feature. Rather, this is also a user model. When we send a document as an attachment in an email, we are passing it around by value. Problem is, this value may be modified by multiple users and the modified copies can come back to you for you to consolidate, which close to impossible to do. Call-by-value is a very bad user model. When you send a link to a web resource in an email, you are passing it around by reference. Everybody then goes to the same place to access it. This elimiates many problems. Call-by-reference is the correct user model in most cases. Of course, when the user is offline, you have to use some type of call-by-value. Modern email servers support this mode when you check download message to local so that you can access your emails when you are offline.
So, CBR for online and CBV for offline.
0 Comments:
Post a Comment
<< Home