[Pitch #2] Property Delegates by Custom Attributes

I was simply pointing out to @DevAndArtist that access to self wasn't the only advantage of the built-in lazy.

More generally, I'd say the Lazy and UserDefault examples highlight a shortcoming of the proposal by forcing things to be part of the storage when they shouldn't. They're what I call bad examples of things you can do with a property delegate. You want a property "delegate" but you need an instance of the delegate for every instance of the property, so anything the delegate needs has to be duplicated everywhere.

I'd be happier if the delegate and the storage were two distinct types: the delegate containing things that need to be stored once, statically, and the storage (provided by the delegate) storing the data of the property (if any) within its container. I suggested something like this earlier, but I'm not sure anyone noticed. It's more complex and has to forgo subscript access (because no inout parameters in subscript), but the two-separate-types aspect is rather convenient. Maybe I should try harder to fit the subscript in that design...

7 Likes