On Sat, Nov 26, 2022 at 3:40 PM Deleu <deleu...@gmail.com> wrote:

>
> As I think more about this, there's nothing about the current RFC in this
> code sample. What's breaking LSP here is the child class doing state
> modification, not PHP.  To further expand that rationale, PHP allows us to
> create child classes. Whether that class will be LSP-safe or not is up to
> us, not up to PHP.
>
> However, the point still stands. Allowing child classes to break readonly
> will make it easier to build code that breaks LSP. The question then
> becomes: why is this being proposed and is it worth it?
>

I cannot help but feel that the way `readonly` is being treated is going to
end up one of those things that is regretted. "Readonly does not imply
immutability". The fact that very nearly *every* single person who has not
worked on the RFCs has at some point been confused by this however should
be very telling.

This comes from two *different* avenues that compound with each other to
*both* make this design head-scratching to me.

First, in virtually all other technical contexts where the term "readonly"
is used, it means that the information/data cannot be altered. That is not
the case with readonly. In PHP, in this implementation, it is not
"readonly" in the sense that it is used everywhere else for computing, it
is "assign once".

Second, the English words "read only", particularly to native speakers,
make this behavior very counterintuitive and confusing. I won't belabor
that point further.

What "read only" really is, is "constructor initialize only". It honestly
has nothing to do with "read" as it's implemented.

I guess I worry that this RFC makes `readonly` even more of a minefield for
PHP developers, increasing the mental load of using it in code while *even
further* watering down the benefits it may provide. It's already designed
in a somewhat counterintuitive way that I feel will be almost completely
replaced in actual code in the wild by "immutable" if PHP ever gets that.

LSP doesn't exist because it is some objectively better way of programming
according to universal laws of entropy or something. It is instead
important because LSP helps programmers be able to predict the behavior of
the program they are writing and reduces the short-term memory load
involved in programming and architecture.

Something that *technically* complies with LSP but makes the program harder
to predict and increases the mental load of programming violates the
*purpose* of LSP. We can argue about whether it is technically correct, but
I feel like that somewhat misses the point: making the language more
capable, more stable, and more predictable.

In other words, I do not believe it is that important or care to argue
about whether this RFC violates LSP. It violates the *purpose* of LSP, and
that's a bigger problem to me personally.

Jordan

Reply via email to