Finding the instance reference of an object

Chuckk Hubbard badmuthahubbard at gmail.com
Wed Oct 29 22:59:46 CET 2008


On Wed, Oct 29, 2008 at 5:27 PM, Dale Roberts <gooberts at gmail.com> wrote:
> Don't you know? There is really only *ONE* case, and, you are right,
> it is Pass By Value. There is no such thing as Pass By Reference at
> the physical CPU level at all, right? If there is, show it to me. Pass
> By Reference is just a silly idiom developed by high-minded CS
> academics to confuse the rest of us. It has no practical use and
> should not be given its own name, when we already have a good an
> proper name for it.
>
> Let me demonstrate with 3 examples of a function definition, and the
> appropriate calling syntax for that function in C++, all sharing the
> common "int i" global variable:
>
> int i = 5;
>
> myfunc(int &val){}   /*CALL:*/ myfunc(i);    // "ByRef" (ya, right!)
> myfunc(int val){}    /*CALL:*/ myfunc(i);    // ByVal
> myfunc(int *val){}   /*CALL:*/ myfunc(&i);   // Joe's ByVal
>
> The first is what all the fakers call "Pass By Reference" - sheesh,
> how naive. We all know that what *really* happens internally is that
> the *address* of val (A VALUE itself, or course) is copied and passed
> on the stack, right? There couldn't be a more straightforward example
> of Pass By Value (unless it's an inline function, or optimized away,
> or possibly when implemented in a VM, or...). It passes the *address*
> of i by value, then we can access the *value* of i too via
> indirection. Hmm, did we need to have two definitions of VALUE there?
> Well, never mind, no one will notice...
>
> The next is obviously pass by value. It's right out there. The value
> of i (which is what we are talking about, right?) is copied out, and
> passed right on the stack in plain daylight where we can all see it.
>
> How about the third? Pass By Value, obviously, of course. This is the
> version you are defending, right? The parameter's value, &i, is
> evaluated and copied right onto the stack, just like in the first
> example. In fact, if you compare the assembler output of the first and
> third examples, you may not even see a difference. Never mind the
> actual contents of that pesky "i" variable that most people are
> referring to when they use the term "value". We don't need to dress up
> example 3 and call it an "idiom" where we are really passing a so-
> called "reference" of the variable "i". Indeed! Don't insult our
> intelligence. We can all see that it's an address passed by value,
> plain and simple.
>
>
> Pass By Reference? So "postmodern". Who needs it. Show me a so-called
> "reference". I've looked at the assembler output and have never seen
> one. There is no such thing.

You are so right!  We also don't need "object-oriented programming".
I looked at the motherboard and I don't see any objects moving around!
 I don't see any values being passed, either.
When I turn on the TV and see Chuck Norris, though, I know it's only a
reference to Chuck Norris, or I would be blinded.  The only case he
needs is "Pass By Roundhouse Kick".

-Chuckk


-- 
http://www.badmuthahubbard.com



More information about the Python-list mailing list