> Le 11 juil. 2025 à 11:38, Nick <p...@nicksdot.dev> a écrit : > > > I am afraid here I do have a strong opinion. Please remember my very first > mail before discussion [1]. > While for Larry the main reason for `readonly` hooks is lazy-initialisation, > for me it is to write less code, to have less noisy classes. > I don’t want to be forced to add readonly to each property. > Now you are proposing a mandatory `cached` modifier. Which means *checks > notes*, I would save 2 characters on each property. > You will understand that this is not in my interest, and not what I am > proposing here. > > But aside from that I do not like to write more code. I honestly don’t see > the benefit of having this modifier in the first place. > How “alternative implementation 2” works now is IMO just good. And it makes > sense because it is limited to the `readonly` context. > There is no technical need for the modifier. As we see, because we have a > working solution at hand. >
The reason I prefer an explicit `cached` modifier (as opposed to have it implied by the fact that the property is readonly), is because it changes the semantics in the following ways: * the get hook is bypassed in more situations than non-cached get hooks; * (depending on the exact implementation details), the result of the get hook is used to populate the backing-store. (Alternatively, we *could* leave the get hook populate it, and just check that the value it returns matches the value on the backing-store. The latter check is mandatory, but I think we could automatically initialise the backing-store if needed.) By contrast, modifiers like `private` or `readonly` do not change the semantics, but only add restrictions on when the relevant operation is allowed. But this is just my opinion for making code more obvious (as opposed to save few keystrokes). If other people agree that `cached` may be implied by `readonly`, I won’t fight against that. > Can we please agree on that it is future scope whether or not non `readonly` > hooks should get such a modifier? Personally, I don’t have objection to relegate non-readonly cached get hooks to future scope. —Claude