Alright niggers

alright niggers,

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.

Attached: 1_nZpsZjDatEzXw5PZP2hGUA.png (1760x989, 248K)

Other urls found in this thread:

youtube.com/playlist?list=PLjn3WmBeabPOUzxcCkzk4jYMGRZMZ6ylF
twitter.com/SFWRedditImages

Nigga are you dumb

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.

How is something so intuitively obvious even in need of an explanation? Maybe this programming thing just isn't for you.

pass by value -> pass the value
pass by reference -> pass the reference

wow that was hard

fist yourself faggot

This is a much better explanation. Now is there more security to passing by reference?

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.

>fist yourself faggot
Expected response of a subhuman

>>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.

You added no value to the thread and got butthurt when you were insulted back.

Attached: ref_vs_val.png (800x600, 26K)

>butthurt
Expected response of a subhuman

50% of Jow Forums barely knows how to access this site
you're in the wrong place for this

Okay. Elaborate please. Is there a way to pass both? What is that called?

You sound like you're retarded and have no idea what you're talking about.

valref

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

closures were implemented in 70s already, just so you know
don't get too enchanted by Go

You mean "call by sharing", when you pass a reference by call by value? Like in Java or C?

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.

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

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.

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.

Attached: pointer.png (694x262, 51K)

Value is the actual thing
Reference refers to the thing
/thread

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

wanted to reply to this user

So how is it different from pass by sharing ?

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

the stanford university has some great lectures about this kind of stuff on youtube

youtube.com/playlist?list=PLjn3WmBeabPOUzxcCkzk4jYMGRZMZ6ylF

its one of the first videos, where he talks about all kinds of stuff concerning pointers and values

Thanks but in which of the 28 similarly titled videos is this explained?

a darkie like you wouldn't understand. but let me waste my time trying to explain

a reference is like an address of where the data is located. a value is the actual data

Attached: 1412377582213-618x672.jpg (618x672, 91K)

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.

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

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

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

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.

>niggers
*sigh*
was being a racist absolutely necessary?

>*sigh*
Back to where you came fron