Given how controversial wrapperValue
has been I’m disappointed that something like this existed in the implementation but was not mentioned here. How were people supposed to discover it? I would have given the same feedback weeks ago had I been aware of this behavior.
If you want to get into philosophy we could debate here what “its” stored properties actually are. Consider the following:
struct Foo {
private var x = 42
}
struct Bar {
var foo: Foo
}
Here, foo.x
is not directly a property of Bar
, but it is part of the storage area of Bar
. Nevertheless, the implementation of Bar
does not have access to it because access control allows the author of Bar
to hide its properties if desired. I don’t see a wrapper type hiding its storage using wrapperValue
as being materially different from this. It is only the mechanism used to encapsulate that is different. There could be endless philosophical debate about this topic and that probably wouldn’t be productive, but I think this perspective should be represented and considered.
If we can’t find ways to support out-of-line initialization and non-synthesized encoding / decoding without exposing $$
and these are considered crucial use cases then perhaps that is a sign that wrapperValue
is a bit too much magic.
I stand by my prior review. If you feel strongly that a wrapper should not be able to hide the actual storage then I am opposed to wrapperValue
. The final design provides no encapsulation tools for library authors. It only provides very magical syntactic sugar with a lot more potential for confusion than usual.
I’ll restate that $foo.binidng
is not that bad and is much more clear about what is going on. I know very experienced and talented programmers who spent a bunch of time scratching their heads trying to figure out how State
turns into Binding
. If you don’t want to go with the original version of this feature which has a lot less magic and offers encapsulation to wrapper authors maybe it should just be dropped.