Is there any functional difference between immutable value types and immutable reference types?
Posted
by
Kendall Frey
on Programmers
See other posts from Programmers
or by Kendall Frey
Published on 2012-06-06T19:31:09Z
Indexed on
2012/06/06
22:47 UTC
Read the original article
Hit count: 426
Value types are types which do not have an identity. When one variable is modified, other instances are not.
Using Javascript syntax as an example, here is how a value type works.
var foo = { a: 42 };
var bar = foo;
bar.a = 0;
// foo.a is still 42
Reference types are types which do have an identity. When one variable is modified, other instances are as well.
Here is how a reference type works.
var foo = { a: 42 };
var bar = foo;
bar.a = 0;
// foo.a is now 0
Note how the example uses mutatable objects to show the difference. If the objects were immutable, you couldn't do that, so that kind of testing for value/reference types doesn't work.
Is there any functional difference between immutable value types and immutable reference types? Is there any algorithm that can tell the difference between a reference type and a value type if they are immutable? Reflection is cheating.
I'm wondering this mostly out of curiosity.
© Programmers or respective owner