I started a new job today...
-
Plus, saying "pass this value by reference" rolls off the tongue way more than "pass the value of the reference to this value"
That second one is the
ref
keyword. Normally you pass a copy of the value (of the reference). That's why it's pass a reference by value.
-
whoever came up with the ref stuff
Honestly i never liked the
ref
key word, i like to useout
when i can instead, i find it a bit more clear in intention.- Without either keyword
- "I will not alter the reference (but I might alter the state of the object if it is mutable)"
- With `ref`
- "I might alter the reference (and i might alter the state of the object if it is mutable)"
- With `out`
- "I will alter the reference (and i might alter the state of the object if it is mutable)"
I'd like to be able to get rid of that parenthetical but honestly immutable data objects usually cause more trouble than they are worth.
-
I'd like to be able to get rid of that parenthetical but honestly immutable data objects usually cause more trouble than they are worth.
And are a great source of resource leaks if you don't implement them just right
-
....huh.... didn't notice before. backtick delimited code blocks don't work in <dl> lists....
-
It vaguely confuses me, since I have long forgotten the difference between pass by value and pass by reference and don't particularly care. So my eyes glaze over while people go blah blah blah you're wrong.
Pass by value is when a function gets a "copy" of the argument, so it can't actually modify the argument, and pass by reference is when a function gets the original argument (technically, a pointer/reference to it) so the function can modify it. Right?
The whole discussion is about the implementation and semantics of SIDE EFFECTS.
-
The whole discussion is about the implementation and semantics of SIDE EFFECTS.
The discussion is about the fact that while everything in C# is pass by value (unless you feel like making it pass by reference), people want to call it pass by reference because they like that wording for something that it doesn't do.
-
The discussion is about the fact that while everything in C# is pass by value (unless you feel like making it pass by reference), people want to call it pass by reference because they like that wording for something that it doesn't do.
That all sounds like KCHHHHHHSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS to me.
-
The discussion is about the fact that while everything in C# is pass by value (unless you feel like making it pass by reference), people want to call it pass by reference because they like that wording for something that it doesn't do.
But it does pass stuff by reference
-
It's simple.
If you pass 3 into a method, and something ++s it, it's now 4 in that method, because its a different int.
The same is true of all types. If you reassign an argument, its a different object reference, so it changes nothing in the caller.
But people think that changing the member of a reference type is equivalent to changing an instance of a value type, because they like being inaccurate.
-
But it does pass stuff by reference
You do not become more correct by saying wrong things more times. A copy is not the same as the original.
-
The leaves in my burrito taste like carrots. Weird, right?
-
3 == 4 in 'pass by reference' land.
-
You do not become more correct by saying wrong things more times. A copy is not the same as the original.
May I draw your attention to
@RaceProUK said:
-
-
You're still wrong. WRONG. WRONG!!!!!!!!
Oh no! Whatever will I do?*proceeds to live a normal life*
-
-
@RaceProUK said:
*proceeds to live a normal wrong life*
FTFY
What I do in my spare time is none of your- oh, you weren't talking about that, were you? ;)
-
@Magus said:
@RaceProUK said:
*proceeds to live a normal wrong life*
FTFY
What I do in my spare time is none of your- oh, you weren't talking about that, were you? ;)
Maybe I was.
-
-
But only because I like the more humanoid types. Cat ears and a tail? Sure.
DERAILMENT COMPLETE
-
The discussion is about the fact that while everything in C# is pass by value (unless you feel like making it pass by reference), people want to call it pass by reference because they like that wording for something that it doesn't do.
Don't mind him, he's the resident Smug Haskell Weenieโข. I like Haskell, but any language with a safe type system is OK by me. I'm the "here's a nickel, kid, go buy yourself a real type system" guy.
-
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?
I don't know. If you said you are passing something by reference outside of a context such as this discussion, I would assume you meant it was qualified byref
. If that's not what you mean, then yes it would be confusing.
-
I don't know. If you said you are passing something by reference outside of a context such as this discussion, I would assume you meant it was qualified by
ref
. If that's not what you mean, then yes it would be confusing.Well, OK, to be fair I don't often use ref, so I rarely say those words anyway (I don't say them when talking about reference types for instance, since reference types can't really be passed around by value).
-
-
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, then swap would work.
No it wouldn't. Allow us to review
swap
:```
void swap(Something a, Something b) {
Something t = a;
a = b;
b = a;
}void caller() {
Something s1 = ...;
Something s2 = ...;
swap(s1, s2);
}Regardless of pass by ref, your swap method will not fulfill its intended purpose. If you are doing pass by ref, your inputs will just end up being identical. If you look closely, you'll see that swap incorrectly does `b = a;` when it should do `b = t;`. Write less buggy code when trying to illustrate a point. Especially when your example is so *short*.