On Tue, May 11, 2021 at 7:45 AM Nikita Popov <nikita....@gmail.com> wrote:
> My thought here is that a constructor with (only) promoted properties is > hardly a constructor at all -- it's more like a special syntax for > declaring properties that happens to re-use the constructor notation, > because that allows it generalize in certain ways. It could have been > implemented with some other syntax that didn't explicitly mention > constructors at all, such as class Point($x, $y, $z) {} or something. > Agreed. I've personally been a little hesitant to start using CPP because of this. Declare constructor parameters AND declare properties AND magically provide a constructor implementation that sets their values. It looks like a constructor, but it's actually a little different. For me, this proposal would really help clear that up. When I see a method with an empty body, I think "this method does have an implementation, and that implementation does exactly nothing." In the case of CPP, this isn't true. The method appears to do exactly nothing, but in fact it has an automatically defined implementation that sets the properties to the given values. When I see a semi-colon-terminated method, I think "this method has no implementation *here*; one will be provided from somewhere else." This is the case in abstract classes and interfaces--the subclass provides the implementation. And it's the case in CPP too--an implementation that sets the properties to the given values is automatically provided. For this reason, I don't see it as inconsistent. The semi-colon means someone else will provide an implementation, and CPP does just that. Regards, --Matthew