On Mon, 29 Jun 2020 at 16:44, Marco Pivetta <ocram...@gmail.com> wrote:
> property accessors seem to perpetuate the bad practice > of getters and setters > Outside of access restrictions, a common use case I've seen for property accessors is lazy-loading, which I know is something you use in other forms. > Máté also linked today ( https://twitter.com/kocsismate90/status/1277625002720968704) that C# 9.0 is getting init-only properties, which looks similar to the RFC linked above. Note that in C# the new "init" keyword is explicitly an extension of property accessors [1], and relates specifically to "object initializers", which PHP does not have; a proposal for them last year [2] was rejected. An existing "readonly" keyword [3] allows you to write a variable only in the constructor, and "init" is mostly needed because object initializers are run too late for this. C# 9.0 also has a bunch of features around immutable data structures in general, including a variant of object initializers called "with-expressions" [4] to solve the "modified clone" problem. [1] https://github.com/dotnet/csharplang/blob/master/proposals/init.md#detailed-design [2] https://wiki.php.net/rfc/object-initializer [3] https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/readonly [4] https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/#with-expressions -- Rowan Tommins [IMSoP]