Re: [RFC] Asymmetric visibility
| From: | Andreas Heigl | Date: | Mon, 08 Aug 2022 08:23:37 +0000 |
| Subject: | Re: [RFC] Asymmetric visibility | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118383@lists.php.net to get a copy of this message | ||
Hey Marco.
On 08.08.22 10:14, Marco Pivetta wrote:
Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0xA8D5437ECE724FE5.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
Heyo Andreas, Casper, On Mon, 8 Aug 2022 at 10:03, Andreas Heigl <andreas@heigl.org> wrote:Your use case might not need them (though actually you are needing them, you just don't use them as language feature but via the static-analysis annotation) But when discussing language features we should always keep ALL users of the language in mind. And if a feature helps in providing ways to build more stable code on the language level then we should think about that from a point of view of *all* users. And when the feature is already used via static-analysis then why not implement that for use by *everyone* and not only those that have static analysis in their CI toolchain. Just my 0.02€ Cheers Andreas -- ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andreas@heigl.org N 50°22'59.5" E 08°23'58" | | https://andreas.heigl.org | +---------------------------------------------------------------------+ | https://hei.gl/appointmentwithandreas | +---------------------------------------------------------------------+Hey Casper. On 08.08.22 09:54, Casper Langemeijer wrote:Similar question as Casper here: I useHi all, In the discussion I sometimes see the terminology 'readonly' and'writable' being used. This is confusing because when the property is an object that itself is mutable, there is nothing read-only about it.The terminology in the RFC seems right to me, and overall it seems solid. However, I'm not convinced this RFC is solving a real issue. I could notfind any reasoning in the RFC, except that Swift has a very similar language feature.To me it solves the topic of making a property readable but not writeable from the public while still allowing it to be written to within the private or protected context. So enforcing usage of a public setter-metbhod but not having to use a getter. Soemthing like this final class Foo {public private(set) string $username;public function changeUsernameTo(string $newUsername): self { if (! newUsernameIsUnique($newUsername) { throw new RuntimeException('The username is not unique'); } $this->username = $newUsername;return $this; }} readonly only solves that for immutable properties but there currently is no way of solving that for mutable properties.readonlyproperties aggressively, and I try to make the state as immutable as possible. In the **extremely** rare cases wherepublic getandprivate setare needed, I rely on traditional getters and setters, which are becoming extremely situational anyway, and still work perfectly fine. If that doesn't work, then PHPStan/Psalm allow declaring@private,@internal,@phpstan-internalor similar mechanisms to restrict scope access.qossmic/deptracalso works wonders here, compared to PHP. > In fact, I'm writing so few getters and setters these days, that I don't see why I'd need getter and setter semantics to creep into the language, especially mutable ones, not even with the reflection improvements.
Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0xA8D5437ECE724FE5.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc