On Tue, Jun 8, 2021, at 4:18 AM, Nikita Popov wrote: > > (Like, for example, if one had a readonly property but wanted to convert > > it to a custom accessor property... what are the subtle knock on effects > > they have to account for, then? There are almost certainly more of them > > than if switching a property from implicit accessors to explicit accessors, > > although off hand I don't know what they would all be.) > > > > > I think this is a legitimate concern to have, but (under the assumption > > > that we can have only one) it's not easy to say which would be > > preferable. > > > Yes, asymmetric visibility is more widely applicable, but at the same > > time > > > I would expect most applications to be bonafide readonly properties. So > > > while asymmetric visibility is more widely applicable, it's also > > imprecise > > > for the majority use case. Which is better? Of course, my assumption here > > > could also be wrong. > > > > As above, I'd love to get some actual data from the C# community on this. > > Lacking that, we're all just guessing.> > > > Well, I think we can get an approximation like this: > > https://beta.grep.app/search?q=%7B%20get%3B%20private%20set%3B%20%7D&filter[lang][0]=C%23 > { get; private set; } 74,281 results > https://beta.grep.app/search?q=%7B%20get%3B%20%7D&filter[lang][0]=C%23 { > get; } 156,304 results > https://beta.grep.app/search?q=readonly&filter[lang][0]=C%23 readonly > 409,585 results > > Note that the "{ get; }" part includes both readonly properties and > get-only abstract properties, so that one is an overestimate. Using > variants like \{\s+get;\s+private set;\s+\} doesn't change the results > materially. > > Unless my methodology is completely borked, the ratio of readonly to > asymmetric visibility seems to be something like 4:1 even as a conservative > estimate. > > Regards, > Nikita
Interesting. I have no particular grounds to challenge your methodology, so I'll accept that C# seems to use readonly much more than asymmetric visibility/accessors. Does C# have a clone-with or equivalent? Even with readonly being useful, I think it's only half the answer without a clean evolvability mechanism beyond "re-type all the fields by hand." CPP removed a ton of that boilerplate, and I'd hate to bring it back. --Larry Garfield -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php