who can definitively explain value vs reference best?
my explanation that a reference is working on the same shit, it's a sculptor sculpting the work of art, while value is taking a blueprint of a car and then working on the actual car without touching the blueprint.
Imagine you have a bunch of bank deposit boxes in a vault. They all have numbers.
Pass by value: You look into deposit box 223, take out the piece of paper that's in it, copy all it says on it to a new piece of paper, put the original back into 223, and put the copy into 556
Reference: You take a new piece of paper and write "look into 223" and put it into 556.
Unsure why that's so complicated.
Adrian Cook
How is something so intuitively obvious even in need of an explanation? Maybe this programming thing just isn't for you.
Samuel Evans
pass by value -> pass the value pass by reference -> pass the reference
wow that was hard
Nathan Martin
fist yourself faggot
This is a much better explanation. Now is there more security to passing by reference?
Brody Garcia
No. You could argue that the implementation of passing by reference (pointers) brings security issues, but that shouldn't be a factor in using one over the other.
Aaron Young
>fist yourself faggot Expected response of a subhuman
Carson Allen
>>Brings nothing to the table >>expects a response >>uses insults to elbow into a conversation which has no utility for either party >>gets mad when shit gets flung back
fuck off and die
Well, nearly every language now is pass by value if I'm correct. So the most interesting thing I've seen, is how Go channels utilize a main routine to direct child routines and if the child routines references the same value in memory, it continues to overwrite. So essentially every child routine (think of it as like IO streams in Node) needs it's own pass by value instance. I just thought it was interesting how if you don't define separate memory instances, the shit will overwrite and continue to output the same routine after the initial first main routine is done. Difficult to explain, but it's like going through a car wash and now that you have, the car wash only blow drys the car, meaning that the last instance just keeps running and running.
Dominic Reed
You added no value to the thread and got butthurt when you were insulted back.
50% of Jow Forums barely knows how to access this site you're in the wrong place for this
Ayden Davis
Okay. Elaborate please. Is there a way to pass both? What is that called?
Landon Flores
You sound like you're retarded and have no idea what you're talking about.
Kayden Johnson
valref
Jordan Miller
well, at least in a language like C which gives you full control over such things, you pass the value of a variable val to a function func by doing func(val) and the reference to val (a pointer which points to the first byte of the block(s) that val occupies by doing func(&val) so passing both would look like func(val, &val) but its kindof superfluous, since if you make your function take a pointer, you can just dereference it like *val and there you have the value
Hunter Reed
closures were implemented in 70s already, just so you know don't get too enchanted by Go
Jackson Gonzalez
You mean "call by sharing", when you pass a reference by call by value? Like in Java or C?
Aiden Phillips
gotcha
In Golang a pointer is designated with the star * and a reference to the value is &. Retard of the question day here...
>>and the reference to val (a pointer which points to the first byte of the block(s)
So, you can have pointer, to a reference of a value in C?
Neat man, cool.
Wtf, is seriously 1/3 of this board populated by stupid niggers? really gotta thin the herd here guys.
Logan Edwards
Nice explanation. Now can you explain what is a pointer with the same example ? Is passing a pointer the same as passing by reference (in languages that allow it)?
Jonathan Gomez
First time I'm hearing about this. Awesome, yes pretty much exactly that. I have no background in Java or C so that makes sense, thanks.
Nathaniel Ramirez
It's a somewhat uncommon term, but it's probably required, since a lot of brainlets claim that C and Java can do call by reference.
Value is the actual thing Reference refers to the thing /thread
Jonathan Thompson
in c a reference to a value is a pointer youre right, if i want to make a pointer, ill do *valptr = some memory address but the address of where a variables value is saved is obtained by doing &val pointer and reference are interchangeable in this context
Robert Reyes
wanted to reply to this user
Ryder Fisher
So how is it different from pass by sharing ?
Jaxon Flores
when you get down to the memory handling, there are literally only two ways to pass a struct in memory, by copying its memory address or by copying the bits residing at that address
Mason Wilson
the stanford university has some great lectures about this kind of stuff on youtube
Call by sharing is the act of passing an adress by call by value. Best way to look at it is C# which has both in a non-retarded way. Basically, call by reference adds another indirection, so that even if you replace the adress directly the adress you passed was changed, too.
Bentley Davis
as i said, its in one of the first ones, if you watch the beginning, hes always explaining what will be covered in each lecture and if youre serious about learning the innards of programming, you should watch them all regardless
Ian Bailey
A variable is a place in memory containing a value A variable value is the value stored in that specific address A variable reference is the value of the memory address where this variable is stored
You're welcome
Jacob Flores
What a dumb fucking explanation. Pass by value: The memory occupied by the value is copied over Pass by reference: A pointer to the memory occupied by the value is copied over
Nicholas Reed
All these analogies are useless. Just use concrete examples instead- create some example functions, passing various objects by value and reference, with printfs before and after calling them demonstrating in which situations the passed object is mutated and in which it is not.
This will build a strong intuition and after they get it you can go into nuances like storing references/ownership/etc.
Aiden Cruz
>niggers *sigh* was being a racist absolutely necessary?