Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-02-04 Thread Larry Garfield
On Wed, Feb 3, 2021, at 8:14 AM, Nikita Popov wrote: > On Mon, Dec 28, 2020 at 9:24 PM Larry Garfield > wrote: > > > There's been a number of discussions of late around property visibility > > and how to make objects more immutable. Since it seems to have been > > well-received in the past, I

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-02-04 Thread Mike Schinkel
> On Feb 3, 2021, at 9:14 AM, Nikita Popov wrote: > > On Mon, Dec 28, 2020 at 9:24 PM Larry Garfield > wrote: > >> There's been a number of discussions of late around property visibility >> and how to make objects more immutable. Since it seems to have been >> well-received in the past, I

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-02-03 Thread Pierre R.
Le 03/02/2021 à 15:14, Nikita Popov a écrit : I've written up an initial draft for property accessors at https://wiki.php.net/rfc/property_accessors, but once again I get the distinct impression that this is adding a lot of language complexity, that is possibly not justified (and it will be

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-02-03 Thread Nikita Popov
On Mon, Dec 28, 2020 at 9:24 PM Larry Garfield wrote: > There's been a number of discussions of late around property visibility > and how to make objects more immutable. Since it seems to have been > well-received in the past, I decided to do a complete analysis and context > of the various

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-10 Thread Larry Garfield
On Sat, Jan 9, 2021, at 7:24 PM, G. P. B. wrote: > On Sun, 10 Jan 2021 at 00:33, Larry Garfield wrote: > > It took a few days, but I am back with some more concrete examples. I > > decided to try and convert PSR-7 to the various options considered in my > > previous post. Here are the results:

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-10 Thread Rowan Tommins
On 10 January 2021 01:24:38 GMT+00:00, "G. P. B." wrote: >Moreover, asymmetric visibility does not prevent mutating an object by >calling the constructor once again as follows: >$obj->__construct(...$args); That's pretty trivial to work around: mark the constructor private and provide one or

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-09 Thread G. P. B.
On Sun, 10 Jan 2021 at 00:33, Larry Garfield wrote: > On Sun, Jan 3, 2021, at 11:29 AM, Olle Härstedt wrote: > > > > I'll disagree slightly. A language feature should introduce more > power than > > > it does complexity. Not everything *can* be made absolutely simple, > but the > > > power it

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-09 Thread Larry Garfield
On Sun, Jan 3, 2021, at 11:29 AM, Olle Härstedt wrote: > > I'll disagree slightly. A language feature should introduce more power than > > it does complexity. Not everything *can* be made absolutely simple, but the > > power it offers is worth it. I'd say it should minimize introduced > >

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-03 Thread Olle Härstedt
2021-01-03 16:55 GMT, Larry Garfield : > On Sun, Jan 3, 2021, at 8:28 AM, Olle Härstedt wrote: > >> >> I like that you connect higher level design patterns with language >> >> design. This is the way to go, IMO. Personally, I'd prefer support for >> >> the Psalm notation `@psalm-readonly`, which

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-03 Thread Larry Garfield
On Sun, Jan 3, 2021, at 8:28 AM, Olle Härstedt wrote: > >> I like that you connect higher level design patterns with language > >> design. This is the way to go, IMO. Personally, I'd prefer support for > >> the Psalm notation `@psalm-readonly`, which is the same as your > >> initonly. Clone-with

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-03 Thread Olle Härstedt
2021-01-02 16:06 GMT, Larry Garfield : > On Fri, Jan 1, 2021, at 5:51 PM, Olle Härstedt wrote: > >> >> The web dev discourse is >> >> one-sided with regard to immutability, >> > >> > Yes, if you've heard any of the regular whining about PSR-7 being an >> > immutable object you'd think it's

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-03 Thread Rowan Tommins
On 2 January 2021 21:25:08 GMT+00:00, Larry Garfield wrote: >If a stream is not seekable, then it would have to consume and destroy >$fp in the process (unset it). So: > >[$line1, $fp2] = read_line($fp); >[$line2, $fp2] = read_line($fp); > >The second line would throw an error that $fp "has

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-02 Thread Paul M. Jones
Hi Rowan and all, I apologize in advance for the wall-of-text; the short questions lead to long answers. > On Jan 2, 2021, at 12:56, Rowan Tommins wrote: > > On 01/01/2021 20:31, Paul M. Jones wrote: > >> The complaints against the incomplete and inconsistent immutability of PSR-7 >> have

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-02 Thread Olle Härstedt
2021-01-02 21:25 GMT, Larry Garfield : > On Sat, Jan 2, 2021, at 12:56 PM, Rowan Tommins wrote: >> On 01/01/2021 20:31, Paul M. Jones wrote: >> > The complaints against the incomplete and inconsistent immutability of >> > PSR-7 have merit. >> >> >> The big mistake of PSR-7, in my view, is mixing

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-02 Thread Larry Garfield
On Sat, Jan 2, 2021, at 12:56 PM, Rowan Tommins wrote: > On 01/01/2021 20:31, Paul M. Jones wrote: > > The complaints against the incomplete and inconsistent immutability of > > PSR-7 have merit. > > > The big mistake of PSR-7, in my view, is mixing immutable objects with > streams, which are

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-02 Thread Rowan Tommins
On 01/01/2021 20:31, Paul M. Jones wrote: The complaints against the incomplete and inconsistent immutability of PSR-7 have merit. The big mistake of PSR-7, in my view, is mixing immutable objects with streams, which are inherently mutable/stateful. I wonder if there are any lessons to be

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-02 Thread Rowan Tommins
On 31/12/2020 14:04, Olle Härstedt wrote: Yes, of course you can find use-cases where immutability is a better choice, just like I can find use-cases where (constrained) mutability is better. The point is not to replace one tool with another, but rather adding another tool to the toolbox. The

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-02 Thread Larry Garfield
On Fri, Jan 1, 2021, at 5:51 PM, Olle Härstedt wrote: > >> The web dev discourse is > >> one-sided with regard to immutability, > > > > Yes, if you've heard any of the regular whining about PSR-7 being an > > immutable object you'd think it's one-sided in favor of mutability. ;-) > > > > As you

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-01 Thread Olle Härstedt
2021-01-01 19:14 GMT, Larry Garfield : > On Thu, Dec 31, 2020, at 8:04 AM, Olle Härstedt wrote: >> 2020-12-31 12:37 GMT, Rowan Tommins : > >> > On 30/12/2020 18:42, Olle Härstedt wrote: >> >>> To put it a different way, value types naturally form*expressions*, >> >>> which mutable objects model

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-01 Thread Paul M. Jones
> On Jan 1, 2021, at 13:14, Larry Garfield wrote: > >> The web dev discourse is one-sided with regard to immutability, > > Yes, if you've heard any of the regular whining about PSR-7 being an > immutable object you'd think it's one-sided in favor of mutability. To characterize it as

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2021-01-01 Thread Larry Garfield
On Thu, Dec 31, 2020, at 8:04 AM, Olle Härstedt wrote: > 2020-12-31 12:37 GMT, Rowan Tommins : > > On 30/12/2020 18:42, Olle Härstedt wrote: > >>> To put it a different way, value types naturally form*expressions*, > >>> which mutable objects model clumsily. It would be very tedious if we had >

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-31 Thread Olle Härstedt
2020-12-31 12:37 GMT, Rowan Tommins : > Hi Mike and Olle, > > > On 31/12/2020 00:24, Mike Schinkel wrote: >> A different perspective is that "withX" methods require a mental >> translation where "addX" methods do not, much like how a person whose >> native language is English will find it a

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-31 Thread Rowan Tommins
Hi Mike and Olle, On 31/12/2020 00:24, Mike Schinkel wrote: A different perspective is that "withX" methods require a mental translation where "addX" methods do not, much like how a person whose native language is English will find it a challenge to (or cannot) "think" in French. I wonder

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Mike Schinkel
> On Dec 30, 2020, at 1:15 PM, Rowan Tommins wrote: > > On 30/12/2020 13:49, Olle Härstedt wrote: >> Uniqueness is when you only allow _one_ reference to an object (or >> bucket of memory). >> [...] >> >> You can compare a builder pattern with immutability vs non-aliasing >> (uniqueness): >>

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-30 21:27 GMT, Olle Härstedt : > 2020-12-30 20:37 GMT, Larry Garfield : >> On Wed, Dec 30, 2020, at 2:16 PM, Olle Härstedt wrote: >> >>> > Ok. You have a benchmark for this? I can make one otherwise, for the >>> > query >>> > example. >>> > >>> > It worries me a little that immutability is

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-30 20:37 GMT, Larry Garfield : > On Wed, Dec 30, 2020, at 2:16 PM, Olle Härstedt wrote: > >> > Ok. You have a benchmark for this? I can make one otherwise, for the >> > query >> > example. >> > >> > It worries me a little that immutability is pushed into the ecosystem >> > as a >> > silver

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Larry Garfield
On Wed, Dec 30, 2020, at 2:16 PM, Olle Härstedt wrote: > > Ok. You have a benchmark for this? I can make one otherwise, for the query > > example. > > > > It worries me a little that immutablility is pushed into the ecosystem as a > > silver bullet. Main reason functional languages are using it

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-30 19:50 GMT, Olle Härstedt : > On Wed, 30 Dec 2020, 20:27 Larry Garfield, wrote: > >> >> > > That's a good summary of why immutability and with-er methods (or >> > > some >> > > equivalent) are more ergonomic. >> > > >> > > Another point to remember: Because of PHP's copy-on-write

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
On Wed, 30 Dec 2020, 20:27 Larry Garfield, wrote: > > > > That's a good summary of why immutability and with-er methods (or some > > > equivalent) are more ergonomic. > > > > > > Another point to remember: Because of PHP's copy-on-write behavior, > full on > > > immutability doesn't actually

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Chuck Adams
On Wed, Dec 30, 2020 at 12:27 PM Larry Garfield wrote: > > If you clone the object, you don't duplicate 15+1 zvals. You duplicate just > the one zval for the object itself, which reuses the existing 15 internal > property entries. If in the new object you then update just the third one, >

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Larry Garfield
On Wed, Dec 30, 2020, at 12:42 PM, Olle Härstedt wrote: > A more motivating example for uniqueness is perhaps a query builder. > > ``` > $query = (new Query()) > ->select(1) > ->from('foo') > ->where(...) > ->orderBy(..) > ->limit(); > doSomething($query); > doSomethingElse($query); >

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Larry Garfield
> > That's a good summary of why immutability and with-er methods (or some > > equivalent) are more ergonomic. > > > > Another point to remember: Because of PHP's copy-on-write behavior, full on > > immutability doesn't actually waste that much memory. It does use up some, > > but far less than

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-30 18:31 GMT, Larry Garfield : > On Wed, Dec 30, 2020, at 12:15 PM, Rowan Tommins wrote: >> On 30/12/2020 13:49, Olle Härstedt wrote: >> > Uniqueness is when you only allow _one_ reference to an object (or >> > bucket of memory). >> > [...] >> > >> > You can compare a builder pattern with

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-30 18:15 GMT, Rowan Tommins : > On 30/12/2020 13:49, Olle Härstedt wrote: >> Uniqueness is when you only allow _one_ reference to an object (or >> bucket of memory). >> [...] >> >> You can compare a builder pattern with immutability vs non-aliasing >> (uniqueness): >> >> ``` >> //

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Larry Garfield
On Wed, Dec 30, 2020, at 12:15 PM, Rowan Tommins wrote: > On 30/12/2020 13:49, Olle Härstedt wrote: > > Uniqueness is when you only allow _one_ reference to an object (or > > bucket of memory). > > [...] > > > > You can compare a builder pattern with immutability vs non-aliasing > > (uniqueness):

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Rowan Tommins
On 30/12/2020 13:49, Olle Härstedt wrote: Uniqueness is when you only allow _one_ reference to an object (or bucket of memory). [...] You can compare a builder pattern with immutability vs non-aliasing (uniqueness): ``` // Immutable $b = new Builder(); $b = $b->withFoo()->withBar()->withBaz();

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-29 21:36 GMT, Rowan Tommins : > On 29/12/2020 10:28, Olle Härstedt wrote: >> I just want to mention that immutability might be applied too >> liberally in the current discourse, and in some cases, what you really >> want is*non-aliasing*, that is, uniqueness, to solve problems related >>

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-30 Thread Olle Härstedt
2020-12-29 22:43 GMT, Rowan Tommins : > On 29/12/2020 18:38, Olle Härstedt wrote: >> Instead of shoe-horning everything into the PHP object system, did >> anyone consider adding support for records instead, which would always >> be immutable, and could support the spread operator for cloning-with

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Rowan Tommins
On 29/12/2020 18:38, Olle Härstedt wrote: Instead of shoe-horning everything into the PHP object system, did anyone consider adding support for records instead, which would always be immutable, and could support the spread operator for cloning-with similar as in JavaScript or OCaml? They could

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Rowan Tommins
On 29/12/2020 10:28, Olle Härstedt wrote: I just want to mention that immutability might be applied too liberally in the current discourse, and in some cases, what you really want is*non-aliasing*, that is, uniqueness, to solve problems related to immutability. I think methods like `withX` is an

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Thomas Nunninger
Am 28.12.20 um 21:23 schrieb Larry Garfield: There's been a number of discussions of late around property visibility and how to make objects more immutable. Since it seems to have been well-received in the past, I decided to do a complete analysis and context of the various things that have

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Olle Härstedt
2020-12-29 15:38 GMT, Larry Garfield : > On Tue, Dec 29, 2020, at 2:26 AM, Marc wrote: >> >> On 28.12.20 21:23, Larry Garfield wrote: >> > There's been a number of discussions of late around property visibility >> > and how to make objects more immutable. Since it seems to have been >> >

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Larry Garfield
On Tue, Dec 29, 2020, at 2:26 AM, Marc wrote: > > On 28.12.20 21:23, Larry Garfield wrote: > > There's been a number of discussions of late around property visibility and > > how to make objects more immutable. Since it seems to have been > > well-received in the past, I decided to do a

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Olle Härstedt
2020-12-29 8:26 GMT, Marc : > > On 28.12.20 21:23, Larry Garfield wrote: >> There's been a number of discussions of late around property visibility >> and how to make objects more immutable. Since it seems to have been >> well-received in the past, I decided to do a complete analysis and context

Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals

2020-12-29 Thread Marc
On 28.12.20 21:23, Larry Garfield wrote: > There's been a number of discussions of late around property visibility and > how to make objects more immutable. Since it seems to have been > well-received in the past, I decided to do a complete analysis and context of > the various things that