What is the main characteristic of pass-by-reference?

  • (11 Pages)
  • +
  • « First
  • 8
  • 9
  • 10
  • 11

154 Replies - 7354 Views - Last Post: 16 November 2017 - 08:22 AM

Poll: What is the main characteristic of pass-by-reference? (1 member(s) have cast votes)

What is the main characteristic of pass-by-reference?

  1. The ability of a method to use a reference(like a pointer or something similar to it) and operate on the original data/object without duplicating it (1 votes [100.00%])

    Percentage of vote: 100.00%

  2. The ability of a method to make the passed variable(argument) point to something else (including the ability to swap object or data) (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#136 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 11:59 AM

View Postandrewsw, on 09 November 2017 - 08:51 PM, said:

Are you seriously suggesting that every time we say "make a change to the student" we have to say "make a change to the student that is accessible via the reference to it"? That ain't gonna happen. Life is too short for such qualifications (and there are plenty of other exciting things to spend time on).

No, on the contrary. But this discussion is about "passing" stuff. If you say that "students"(objects) are being passed by reference, some are pretty quick to slap you with "no, everything is being passed by value"
Was This Post Helpful? 0
  • +
  • -

#137 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6384
  • View blog
  • Posts: 25,783
  • Joined: 12-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 12:14 PM

I don't know anyone who slaps that. It is a minor technical point of discussion to say that the reference is actually passed by value. Nearly everyone will let the phrase "students (objects) are being passed by reference" pass without comment.
Was This Post Helpful? 0
  • +
  • -

#138 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 12:47 PM

As noted much earlier in this thread, most natural languages are fuzzy, and English is even more so. The language evolves and becomes more colloquial even though the words may not mean what they originally meant.

For example, "decimate" used to mean the punishment for troops where they had to kill one of out every ten of their own. Now it means to kill or destroy a large percentage of something. How did we get from 10% to over 50%?

Why do we "fly on an airplane" instead of "fly in an airplane"?

So it seems that the phrase "pass (an object) by reference" has come to be accepted by people skilled in the art to mean that a value that represents a pointer or identifier for the object is passed. The more accurate phrase would be "pass a reference (to an object)".

This was part of the point I was trying to make with my post several pages back about simply passing a filename or an array index to try to refer to an object. You didn't seem to have problems with the idea of the filename as a reference to a file system object, but didn't like the idea of an index as a reference to an array element.
Was This Post Helpful? 1
  • +
  • -

#139 jimblumberg  Icon User is offline

  • member icon

Reputation: 5336
  • View blog
  • Posts: 16,619
  • Joined: 25-December 09

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 01:40 PM

Quote

View Postjimblumberg, on 09 November 2017 - 07:47 PM, said:
Yes you should pass large objects to functions either by pointer or by reference but there is nothing stopping you from passing any object by value.

But remember if you pass the object by value, a copy will be made (this is what pass by value means) and any changes made to that object in the function will not be reflected in the object in the calling function (this is the consequence of passing by value).

The reason to pass by pointer or by reference (with the correct const qualifier) is to avoid the potential expensive copy operation inherent in pass by value and to allow changes made in the function to be reflected in the calling function.

Quote

Isn't that what I've been saying all along?

No, absolutely not. You are saying that the actual object is passed into the function, which is incorrect.

Please show me a picture showing how you intend to pass any object to any function in C/C++ without creating a copy.

Jim
Was This Post Helpful? 1
  • +
  • -

#140 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10690
  • View blog
  • Posts: 18,310
  • Joined: 19-March 11

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 02:25 PM

ccdan, I've proposed a language change that seems to me that it addresses your concerns. Is there any reason why saying "pass by location" doesn't solve this problem for you?
Was This Post Helpful? 0
  • +
  • -

#141 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 03:34 PM

View Postjimblumberg, on 09 November 2017 - 10:40 PM, said:

No, absolutely not. You are saying that the actual object is passed into the function, which is incorrect.

Please show me a picture showing how you intend to pass any object to any function in C/C++ without creating a copy.

Jim

There ya go:

View Postccdan, on 23 October 2017 - 05:42 PM, said:

When you have "pass-by-something" that "something"(which could be a number, an image, etc.) will somehow be transferred to a method so that the method can operate on that data(display a number, an image, or whatever).

When you have pass-by-value, that data will be DUPLICATED and the method will operate on that DUPLICATE, without touching the ORIGINAL.

When you have pass-by-reference, the memory address the passed variable points to will be used by a method, so the method will operate on the ORIGINAL data(that is, there won't be any copy of that data) using that memory address. It's completely irrelevant how that address got there(sure it is copied, there's no other way to do it)

That's exactly what Bjarne Stroutrup said: We use const references to pass objects

So basically you are saying that Stroustrup and Scott Meyers are using incorrect terminology. :sigh:
Was This Post Helpful? 0
  • +
  • -

#142 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13495
  • View blog
  • Posts: 53,911
  • Joined: 12-June 08

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 03:37 PM

Why would it be a shock? Are they not using fuzzy communication like the rest of us? Classic mountain out of a mole hill.
Was This Post Helpful? 0
  • +
  • -

#143 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10690
  • View blog
  • Posts: 18,310
  • Joined: 19-March 11

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 08:50 PM

View Postccdan, on 09 November 2017 - 05:34 PM, said:

That's exactly what Bjarne Stroutrup said: We use const references to pass objects

So basically you are saying that Stroustrup and Scott Meyers are using incorrect terminology. :sigh:/>


So what you're saying is that references are passed to functions and these references are used to act on those objects.
What you will certainly agree with is that these references are passed by value. (see the quotes you just supplied if you have any doubt on this score, for example "When you have pass-by-value, that data will be DUPLICATED and the method will operate on that DUPLICATE, without touching the ORIGINAL.")

This is not in any way different from anything anyone else is saying. There are no facts that anyone here disagrees on. Why are you arguing?
Was This Post Helpful? 0
  • +
  • -

#144 jimblumberg  Icon User is offline

  • member icon

Reputation: 5336
  • View blog
  • Posts: 16,619
  • Joined: 25-December 09

Re: What is the main characteristic of pass-by-reference?

Posted 09 November 2017 - 09:04 PM

Quote

So basically you are saying that Stroustrup and Scott Meyers are using incorrect terminology.

No, I have been saying that you're misreading/misunderstanding what is being said by those individuals.

Quote

When you have pass-by-value, that data will be DUPLICATED and the method will operate on that DUPLICATE, without touching the ORIGINAL.

When you have pass-by-reference, the memory address the passed variable points to will be used by a method, so the method will operate on the ORIGINAL data(that is, there won't be any copy of that data) using that memory address. It's completely irrelevant how that address got there(sure it is copied, there's no other way to do it)


This sure sounds like you now agree that in C/C++ everything is passed by value or am I misunderstanding something? By the way it is not irrelevant how it got there, it is precisely the point.

Jim
Was This Post Helpful? 0
  • +
  • -

#145 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: What is the main characteristic of pass-by-reference?

Posted 10 November 2017 - 10:50 AM

<grin>Next thing you know, ccdan will be asking why people list HTML on their resumes as a programming language, when we all know that it is not a programming language.</grin>
Was This Post Helpful? 0
  • +
  • -

#146 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10690
  • View blog
  • Posts: 18,310
  • Joined: 19-March 11

Re: What is the main characteristic of pass-by-reference?

Posted 10 November 2017 - 11:49 AM

Or why iTunes lists something like Matt Molloy's recording of the Gold Ring as a "song", when we all know it's a tune.
Or why we park on driveways and drive on parkways.
Was This Post Helpful? 0
  • +
  • -

#147 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 14 November 2017 - 09:29 AM

View Postjon.kiparsky, on 10 November 2017 - 05:50 AM, said:

So what you're saying is that references are passed to functions and these references are used to act on those objects.
What you will certainly agree with is that these references are passed by value.

While I also agree that references are passed by value, I disagree that they're the main thing being passed.

View Postjon.kiparsky, on 10 November 2017 - 05:50 AM, said:

This is not in any way different from anything anyone else is saying. There are no facts that anyone here disagrees on. Why are you arguing?

Many seem to disagree that objects are also being passed using the above mentioned references.
Was This Post Helpful? 0
  • +
  • -

#148 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13495
  • View blog
  • Posts: 53,911
  • Joined: 12-June 08

Re: What is the main characteristic of pass-by-reference?

Posted 14 November 2017 - 09:32 AM

Ah.. here I thought this thread was going to die a natural death.. nope.. gotta throw out a line with a "Many seem to...".
Was This Post Helpful? 0
  • +
  • -

#149 jimblumberg  Icon User is offline

  • member icon

Reputation: 5336
  • View blog
  • Posts: 16,619
  • Joined: 25-December 09

Re: What is the main characteristic of pass-by-reference?

Posted 14 November 2017 - 09:47 AM

Well since "many" could be construed to mean "everyone except ccdan", he is correct, sort of.


The only time an object is passed into a function is when passing by value and then that object is a copy of the original.

No matter what you do the original object is never passed into a function.


Jim

This post has been edited by jimblumberg: 14 November 2017 - 09:48 AM

Was This Post Helpful? 1
  • +
  • -

#150 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 15 November 2017 - 07:57 AM

View Postjimblumberg, on 14 November 2017 - 06:47 PM, said:

No matter what you do the original object is never passed into a function.

If it's not passed into a function, then it can't be processed by a function. A display function wouldn't be able to display an object if the data that forms that object would find itself, at some point, inside the function body. The same with a function that modifies a value via a reference. That value would have to get inside the function in order to be modified by some mechanism(for example a conditional increment operation)

This post has been edited by ccdan: 15 November 2017 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

  • (11 Pages)
  • +
  • « First
  • 8
  • 9
  • 10
  • 11