Re: [RFC] Data Classes
On Sat, Nov 23, 2024, at 16:22, Rowan Tommins [IMSoP] wrote:
> On 23/11/2024 13:11, Rob Landers wrote:
>> Born from the Records RFC (https://wiki.php.net/rfc/records) discussion, I would like to
>> introduce to you a competing RFC: Data Classes (https://wiki.php.net/rfc/dataclass).
>
>
> Thank you for continuing to think about this, and PoC code is always useful to work through the
> implications.
>
> It seems like this is going in a very similar direction to the work Ilija shared in April: https://externals.io/message/122845 and https://github.com/php/php-src/pull/13800
>
> My knowledge of the engine isn't good enough to compare the two PRs, but the descriptions
> seem very similar. The main differences seem to be details mentioned in one draft and not the other:
>
>
> - You have described details for constructors and inheritance, which Ilija left as open
> questions
> - Ilija had considered how instance methods should behave, proposing a "mutating"
> keyword and "!" call-site marker. Your RFC doesn't discuss this - the changeName
> example shows behaviour *inside* the method, but not behaviour when *calling* it
>
> Is it just an oversight that you didn't link to the previous discussion, or had you not
> realised how similar the proposals would end up? Either way, this looks like ripe ground for
> collaboration, unless there is some fundamental disagreement about the approach.
>
>
>
> --
> Rowan Tommins
> [IMSoP]
Yes, this is mostly about "composability" vs. dedicated syntax. A bare "data
class" is very similar to struct while a "final readonly data class" is very similar
to records.
> Is it just an oversight that you didn't link to the previous
> discussion, or had you not realised how similar the proposals
> would end up?
Yes, it is an oversight! I didn't even think to link to it. To be fair, I also didn't link
to the records RFC. I've updated the RFC with links. While some behavior is similar to what
Ilija described, it is mostly a natural progression of adding a data
modifier to
classes. There's no special syntax because classes already have a well-defined syntax.
> Your RFC
> doesn't discuss this - the changeName example shows behaviour
> *inside* the method, but not behaviour when *calling* it
An interesting observation, can you explain more as to what you mean? The changeName example is
simply about constructors—whose behavior is mostly due to engine limitations. You can't very
easily see what happens inside a constructor from outside a constructor (usually).
— Rob
Thread (17 messages)