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.


  • FoxDev

    @Bort said:

    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.



  • @RaceProUK said:

    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.



  • @RaceProUK said:

    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.


  • Grade A Premium Asshole

    @Bort said:

    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.

    @RaceProUK said:

    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.



  • @RaceProUK said:

    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 have SomeClass o; and use o, you're talking about the reference to o, not the thing it points to. You can arguably get closer when you say something like o.some_field, but now you're talking about a part of the object, so still not the object itself.

    @RaceProUK said:

    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 sudden swap 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) and foo(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.


  • FoxDev

    @Bort said:

    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 😛


  • ♿ (Parody)

    @Magus said:

    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.



  • @RaceProUK said:

    No, because "they're", "their" and "there" are operationally different.

    Nope. They would be descriptive terms being used incorrectly. Analogy holds.



  • @RaceProUK said:

    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, then swap would work.


  • FoxDev

    Let's be honest: in how many situations does it actually matter?



  • @RaceProUK said:

    Let's be honest: in how many situations does it actually matter?

    Any time you say some_parameter = blah in a function.

    (Well, not any time, but many times.)


  • ♿ (Parody)

    @RaceProUK said:

    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.



  • @EvanED said:

    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?


  • Grade A Premium Asshole

    @RaceProUK said:

    Let's be honest: in how many situations does it actually matter?

    One usage gives @Bort an aneurysm, the other does not.


  • FoxDev

    I understand all the differences and weirdnesses; my only beef is why there's this level of pendantry around two essentially identical operations 😕



  • @RaceProUK said:

    essentially identical operations

    If they were, this discussion wouldn't happen.


  • FoxDev

    @Bort said:

    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 ;)



  • @Bort said:

    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.


  • kills Dumbledore

    @Polygeekery said:

    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.



  • @Magus said:

    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.


  • kills Dumbledore

    Is a reference the same as a referer?


  • ♿ (Parody)

    @RaceProUKblakeyrat said:

    Let's be honest: in how many situations does it actually matter?

    This conversation feels really familiar.


  • ♿ (Parody)

    @RaceProUK said:

    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.



  • @boomzilla said:

    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");
    }
    

    }

    I have seen this happen once in more complex code. We did no have fun.

    :wtf: // breaks code blocks? Also weird code formatting



  • @Piko said:

    // 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!



  • @Maciejasjmj said:

    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!



  • @Magus said:

    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.


  • FoxDev

    Not :wtf:y enough; the Perl script needs to be a created by a Python script created by a Ruby gem running on Lunix ;)


  • BINNED

    @RaceProUK said:

    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?


  • FoxDev

    @Onyx said:

    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



  • @Bort said:

    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.



  • @RaceProUK said:

    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.



  • @Onyx said:

    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


  • BINNED

    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?



  • @Piko said:

    Yeah you are right


  • BINNED

    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 the AReference function, I can overwrite SomeMethod's copy of intList with a new object.



  • @powerlord said:

    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 function AReference, the compiler actually sees a reference to the intlist variable you passed in from SomeMethod, and it's silently dereferencing that on every mention; the effect is to substitute intlist itself, not just a copy, for every occurrence of list in the function body.

    When AReference does list.Add(2), it's actually doing a double dereference: list is dereferenced to find intlist, which is then itself dereferenced (because it's a reference type) to find the object whose Add() 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" ;)


  • ♿ (Parody)

    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.


Log in to reply