I started a new job today...
-
It's a terminology distinction, not an operational distinction. Maybe you disagree with the terminology, I'm not fond of it either, but like I just said, it doesn't matter what sounds right to you. What matters is having a shared understanding of what words mean.
-
Sort of...
Let others join the conversation
This topic is clearly important to you – you've posted more than 27% of the replies here.
Are you sure you're providing adequate time for other people to share their points of view, too?
FUCK OFF MY WORK IS NOT DONE HERE YET!
What pass-by-reference allows that pointers/"references" do not is the ability to change a symbol in the calling scope. Which normally cannot be done. Image the set of local variables in a method are members of a struct. You're sharing memory between your local variable struct and the memory of the called scope's local variable struct.
When a method takes an argument by reference, it's local variable is an alias for the same memory as the variable in the calling scope. This is a step away from having two pointers that have the same value.
Yeah, so it depends on which level we're talking, are we in the language or in the language's implementation?
-
The biggest problem here is that if you equate "pass an object by reference" with "pass a reference to an object by value" you still have to deal with what "pass a reference to an object by reference" becomes in that terminology. And you also have to deal with the fact that everything in C# is "pass by value" unless otherwise stated, and somehow get that to all work together. The terminology actually makes more sense than the except kinda not terminology you use.
-
It's a terminology distinction, not an operational distinction
So I was right: it's pendantic dickweedery most extreme, caused by some puritans having sand in their vaginas
@Magus said:The biggest problem here is that if you equate "pass an object by reference" with "pass a reference to an object by value" you still have to deal with what "pass a reference to an object by reference" becomes in that terminology.
Not really; I know what all those mean, and know when and where they apply
-
This is why I'd rather pass concepts around.
-
Not really; I know what all those mean, and know when and where they apply
And that's cool, but most people don't know the difference, which means that if you insist on this terminology, you are completely incapable of communicating with people who are not, in fact, yourself, and who use different inaccurate definitions.
-
So I was right: it's pendantic dickweedery most extreme, caused by some puritans having sand in their vaginas
No, you're just speaking gibberish.
-
Where's the nearest liquor store?
What's your location? I have drank in enough places that I would almost be willing to pit myself against Google Maps in speed for finding the closest place to get shit faced.
-
When a simple variable is passed as the parameter to any method, it is passed as a value. This means that the value contained by the variable that is passed as the parameter is copied to the variables of the method, and if inside the method these values are changed or modified, the change is not reflected in the actual passed variable.
https://blog.udemy.com/csharp-pass-by-reference/
The parameter is implemented by providing an access path to the actual parameter from the formal parameter. Actions written as if they use or change the formal parameter use or change the actual parameter instead.
i.e. not what happens in C# without the ref keyword.
I can do this all day.
(69 upvotes) Passing by pointer is passing by reference...
uuuuuuuuuuuuuuuuuuuuggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhh.........
Apparently stupidity is only increasing in popularity.
it's pendantic dickweedery most extreme
Maybe. But this is like someone explained to you the difference between "they're", "their" and "there" and instead of starting to use them correctly, you just say "they sound the same to me, so whatever".
Whatever indeed.
But if I worked with you and you said something about passing a parameter by reference, I would insert the ref keyword for that parameter just to spite you.
PS - computers are pedantic dickweeds, if you're going to work on them, you need to appreciate subtleties.
-
So… I can have a reference to something I can't have… except I do have the thing I can't have, else what on Avalice is the reference referring to?
It exists, but you can't talk about it directly. The semantics of Java and C# (class type) references are the same as C pointers, but in Java and C# you don't get a*
operation. So if you haveSomeClass o;
and useo
, you're talking about the reference too
, not the thing it points to. You can arguably get closer when you say something likeo.some_field
, but now you're talking about a part of the object, so still not the object itself.But what I don't see is the distinction between passing a reference by value, and passing an object by reference; to me, they're the same operation.
So in some sense, even though I've been speaking pretty unequivocally, the difference is less clear than I'd like to admit. And that's because of the following:From one perspective, the "problem" isn't the calling convention at all, but all the other language's behaviors; in particular, the fact that
a = b
does reference assignment rather than copying an object. If the semantics of assignment were that it would copy an object rather than make a new alias, but calls still worked the same way as they do, then suddenly functions would look much much much more like "true" call-by-reference, because now all of a suddenswap
starts working.It's the fact that calls and assignments both work at the same level of indirection that means that it's not. And I agree with @Bort; I don't think that "call by reference" is a good name for those semantics nowadays because of the popularity of the term "reference" to describe object pointers in most languages (which post-dates "call by reference"). But because
foo(SomeClass o)
andfoo(SomeClass ref o)
are so different, we still need some term to use to make that distinction, and "pass by reference" is what we've got.
-
Don't worry about, now I just need a gas station and a lighter.
-
But this is like someone explained to you the difference between "they're", "their" and "there" and instead of starting to use them correctly, you just say "they sound the same to me, so whatever".
No, because "they're", "their" and "there" are operationally different.
@Bort said:But if I worked with you and you said something about passing a parameter by reference, I would insert the ref keyword for that parameter just to spite you.
And if you kept that up, you'd be soon reported to management for being a dick
-
But I'd say the majority of people don't know the difference.
The problem is that they hid the details of the pointers vs references from the programmer, so it's not obvious what's really going on.
-
No, because "they're", "their" and "there" are operationally different.
Nope. They would be descriptive terms being used incorrectly. Analogy holds.
-
No, because "they're", "their" and "there" are operationally different.
So are pass-by-reference the way @Bort and I mean it and pass-a-reference-by-value. I really don't know what bort meant by "It's a terminology distinction, not an operational distinction" because it is an operational distinction. If it wasn't, thenswap
would work.
-
Let's be honest: in how many situations does it actually matter?
-
Let's be honest: in how many situations does it actually matter?
Any time you saysome_parameter = blah
in a function.(Well, not any time, but many times.)
-
And passing the object by reference.
You're passing a pointer to the object (by value). Your variable that "holds" a reference type is really holding a pointer to that object (which AIUI is why it's called a reference type). If the called method assigns a different value to the variable that receives the pointer, the caller won't be affected (unless you used the
ref
keyword).You can modify the contents of that reference type in the called method because the method got handed a pointer telling it where all the goodies of that object live. But if you use
ref
, then you get a pointer to a pointer. The language does the dirty work that you'd have to do in C/C++ to make it easy to use the object, but you can fuck with the method that called you by replacing what it thinks that variable is, because it gave you a pointer to where it's storing that pointer.
-
I really don't know what bort meant by "It's a terminology distinction, not an operational distinction" because it is an operational distinction.
Sorry, I meant that racepro seems to understand how the language works, but was using the term incorrectly, as is 99% of everyone.
Butt now I'm ascared to ax tis question: if 99% of peeple are using a word wrong, ain't it right way anyhow?
-
Let's be honest: in how many situations does it actually matter?
One usage gives @Bort an aneurysm, the other does not.
-
I understand all the differences and weirdnesses; my only beef is why there's this level of pendantry around two essentially identical operations
-
-
Butt now I'm ascared to ax tis question: if 99% of peeple are using a word wrong, ain't it right way anyhow?
Language is ultimately defined by usage, so…Also, nice @accalia/correct ratio ;)
-
Yes, and you're passing the reference (implemented as a pointer, but we're not supposed to know that) by value.
I know that "passing a reference" sounds like "passing by reference" but the later phrase has a specific meaning that is being misused when...
This sounds like pedantic dickweedery more than anything.
-
A technology company without turnover is dying
Almost everyone I work with has been there for 10 years or more. I've been there 6 months and starting to think it might be time to start looking for somewhere else.
-
I started a new job about 5 months ago, I transitioned from webdev (backend) to gamedev (finally! always wanted that but never was really sure where & how...), and just now, after 5 months, I'm finally starting to feel getting "less out of my depth".
Yes, the feel is normal in basically any programming jobs, Lasts shorter if it's just about getting to know the codebase, and longer when you also need to get to know the used technology, of course.
-
C# passes all things by value, but the value in this case is essentially a pointer
A reference is passed,
so it is pass by reference.
Q. E. D., bitches.yeah, yeah, I know it's not really, but I couldn't resist.
-
Is a reference the same as a referer?
-
@
RaceProUKblakeyrat said:Let's be honest: in how many situations does it actually matter?
This conversation feels really familiar.
-
my only beef is why there's this level of pendantry around two essentially identical operations
Because it's nice to be able to talk about something. I'm not sure why you don't want to communicate clearly.
-
I'm not sure why you don't want to communicate clearly.
It's probably related to her odd ways of spelling.
Filed under: Customising colours
-
I can't produce a C# example ( I know nothing about C#) but about pass reference by value vs pass by reference it all being pedantry :
Java is pass by value so you can get things like this:import java.util.ArrayList;
public class Foobar {public static void main(String[] args) { ArrayList<Integer> ok = new ArrayList<Integer>(); ArrayList<Integer> fail = new ArrayList<Integer>(); Success(ok); Success(fail); Failure(fail); print(ok); print(fail); /* Result : 01234 01234 */ /* NOT 01234 01234100101102103104 */ } public static void Success(ArrayList<Integer> foo){ /*Adding some dumb numbers to the object */ for (int i=0 ; i< 5 ; i++ ){ foo.add((Integer)i); } } public static void Failure(ArrayList<Integer> foo){ /* Java is pass by value foo is a reference passed by value the assignment below wont hold outside the scope of the method */ foo=new ArrayList<Integer>(); for (int i=0 ; i< 5 ; i++ ){ foo.add((Integer) (i+100)); } } public static void print(ArrayList<Integer> foo){ /* Print some dumb numbers */ for(Integer num : foo){ System.out.print((int)num); } System.out.print("\n"); }
}
// breaks code blocks? Also weird code formatting
-
// breaks code blocks? Also weird code formatting
import java.util.ArrayList; public class Foobar { public static void main(String[] args) { ArrayList<Integer> ok = new ArrayList<Integer>(); ArrayList<Integer> fail = new ArrayList<Integer>(); Success(ok); Success(fail); Failure(fail); print(ok); print(fail); /* Result : 01234 01234 */ /* NOT 01234 01234100101102103104 */ } public static void Success(ArrayList<Integer> foo){ //Adding some dumb numbers to the object for (int i=0 ; i< 5 ; i++ ){ foo.add((Integer)i); } } public static void Failure(ArrayList<Integer> foo){ // Java is pass by value foo is a reference passed by value the assignment below // wont hold outside the scope of the method foo=new ArrayList<Integer>(); for (int i=0 ; i< 5 ; i++ ){ foo.add((Integer) (i+100)); } } public static void print(ArrayList<Integer> foo){ // Print some dumb numbers for(Integer num : foo){ System.out.print((int)num); } System.out.print("\n"); } }
better?
-
Why don't you put those comments above the method signature so they get included in the java doc?
Oh, what, was that off-topic? I don't give a shit!
-
A reference is passed, so it is pass by reference. Q. E. D., bitches.
But that's my whole point! You pass a copy of the reference, not the reference itself, unless you use
ref
!
-
I don't know if I'll ever get over hand editing XML that generates C# that generates XML.
You should just write yourself a little Perl script that edits the XML that generates the C# that generates the XML for you. With regexes.
-
Not y enough; the Perl script needs to be a created by a Python script created by a Ruby gem running on Lunix ;)
-
Ruby gem running on Lunix
That's too simple. Make that FreeBSD and we can talk.
Also, gem? Dafuq? What is it with all these names lately? "Library" and "module" not hip enough for today's kids any more?
-
Also, gem? Dafuq? What is it with all these names lately? "Library" and "module" not hip enough for today's kids any more?
Not for the Ruby community, anyway
-
C# has a keyword for doing pass-by-ref, but people think it's still pass-by-ref even if you don't use the KEYOWR D QRGR AARGRGARRG AAAA!
This is because reference types actually implement assign-by-reference semantics, and give you no syntactic clues that the reference is not actually the thing-referred-to.
Passing a parameter by value is equivalent to assignment, so when you pass a reference type by value, the value you're actually copying is the reference. The net effect is exactly the same as what you'd get in a language like FORTRAN that does not support reference types generally, but does pass subroutine parameters by reference.
When you use by-reference parameter passing to pass a subroutine argument that is itself a reference type, what the subroutine code actually ends up working with is a reference to a reference. Use of that parameter within the subroutine can then involve double-indirection with no syntactic clues at all that this is what's going on, so it's no wonder people get confused.
-
Not y enough; the Perl script needs to be a created by a Python script created by a Ruby gem running on Lunix
Oh come now. There's being silly for fun, and then there's reimplementing Discourse.
-
Also, gem? Dafuq? What is it with all these names lately? "Library" and "module" not hip enough for today's kids any more?
You're one to talk:
@Onyx said:jam noodle video
would install a video nodule, for example.
-
Code block was doing weird stuff depending on how I wrote the comments. Plus this is code I wrote just for the sake of this thread, It does not exist any more, it died in a fire. Also reasons
Yeah you are right
-
That was an intentional riff on stuff like gem. I knew about that stuff before, I just didn't have a proper chance to bitch about it before.
Or do you doubt my ability to make metacommentary about the state of the industry?
-
-
Good to know. When are you leaving?
-
I can write a quick C# example:
Suppose I call SomeMethod below:
private void NotAReference(List<int> list) { list = new List<int>(); list.Add(2); } private void AReference(ref List<int> list) { list = new List<int>(); list.Add(2); } public void SomeMethod() { var intList = new List<int>(); intList.Add(1); // intList is currently a List with a single value: 1 NotAReference(intList); // intList is currently a List with a single value: 1 AReference(intList); // intList is currently a List with a single value: 2 }
Because it's a
ref
arg in theAReference
function, I can overwriteSomeMethod
's copy ofintList
with a new object.
-
Because it's a ref arg in the AReference function, I can overwrite SomeMethod's copy of intList with a new object.
Correct. Because where you see
list
inside functionAReference
, the compiler actually sees a reference to theintlist
variable you passed in fromSomeMethod
, and it's silently dereferencing that on every mention; the effect is to substituteintlist
itself, not just a copy, for every occurrence oflist
in the function body.When
AReference
doeslist.Add(2)
, it's actually doing a double dereference:list
is dereferenced to findintlist
, which is then itself dereferenced (because it's a reference type) to find the object whoseAdd()
method needs invoking.And all of this happens without a shred of syntax in the actual
list.Add(2)
statement to tell you what's going on. Shenanigans of this sort would never have been allowed in a respectable language like C. Yes, it saves what amounts to boilerplate made of dereferencing operators, but at what cost? Scarcely anybody understands :WTF: their code actually does any more. It's abstractions all the way down.
-
I like how this has devolved from "I got a new job" to "GRR PASS BY REFERENCE DOESN"T EXIST GRR"
On a side note, if I'm telling someone that I pass something in C# by reference, or by value, using those exact words, does that confuse anybody? Yeah, saying "pass by reference" doesn't describe how it works internally at all, but does it need to? Those who know how C# works will know what I mean, and those who don't know how C# works, well, there's always Google if they're curious.
Plus, saying "pass this value by reference" rolls off the tongue way more than "pass the value of the reference to this value" ;)
-
If you're explicit on which reference (i.e., what does the reference refer to) you're passing, all is good. I guess we should blame whoever came up with the
ref
stuff for the language for reusing the word. I'm sure @blakeyrat has some choice words for the way they have confused everyone.