Skip Menu |

This queue is for tickets about the Readonly-Tiny CPAN distribution.

Report information
The Basics
Id: 111169
Status: resolved
Priority: 0/
Queue: Readonly-Tiny

People
Owner: BMORROW [...] cpan.org
Requestors: ether [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 4



Subject: Comparison to Const::Fast?
It would be helpful if the documentation described how this was different from/superior to Const::Fast.
Subject: Re: [rt.cpan.org #111169] Comparison to Const::Fast?
Date: Wed, 13 Jan 2016 22:10:51 +0000
To: Karen Etheridge via RT <bug-Readonly-Tiny [...] rt.cpan.org>
From: Ben Morrow <ben [...] morrow.me.uk>
Karen Etheridge via RT <bug-Readonly-Tiny@rt.cpan.org> wrote: Show quoted text
> It would be helpful if the documentation described how this was > different from/superior to Const::Fast.
I'm reluctant to upload Yet Another version in such short order, so for now I'll just explain here: The important differences from Const::Fast are: 1. It does not perform an assignment; it returns a readonly structure. For the situations where I wanted it, this is more useful; in particular, I had a bug where a Moo lazy build method was building a structure that was supposed to be constant, and some other part of the program was accidentally changing it. For a build method this calling convention is more useful. I have also used it to assign a ro value to a 'state' variable, which is impossible with C::F or Readonly. 2. It does not attempt to clone deep structures. C::F not only clones the assigned structure (...sometimes), it makes multiple copies of any internal cross-references, turning the whole structure into a plain tree. This is not always useful, and, IMHO, not part of the job of a 'readonly' module. 3. It has a readwrite function; I was not sure about including this, given its potential danger, but it is useful in cases like a shared cache structure, that should normally be readonly to catch accidental modification, but which occasionally needs updating. I will update the documentation to include this, but I don't think I'll make another upload until I have some functional changes to include. Ben
On Wed Jan 13 17:11:12 2016, ben@morrow.me.uk wrote: Show quoted text
> 1. It does not perform an assignment; it returns a readonly structure. > For the situations where I wanted it, this is more useful; in > particular, I had a bug where a Moo lazy build method was building a > structure that was supposed to be constant, and some other part of the > program was accidentally changing it. For a build method this calling > convention is more useful. I have also used it to assign a ro value to a > 'state' variable, which is impossible with C::F or Readonly.
Sounds entirely reasonable to me. In Const::Fast I tried to make a drop-in replacement for Readonly, it's not my first choice of interface either. Show quoted text
> 2. It does not attempt to clone deep structures. C::F not only clones > the assigned structure (...sometimes), it makes multiple copies of any > internal cross-references, turning the whole structure into a plain > tree. This is not always useful, and, IMHO, not part of the job of a > 'readonly' module.
Cloning deep structures is because it may share a part of the graph with something else that shouldn't be read-only. Breaking internal cross-references is unintentional and I consider that a bug. Show quoted text
> 3. It has a readwrite function; I was not sure about including this, > given its potential danger, but it is useful in cases like a shared > cache structure, that should normally be readonly to catch accidental > modification, but which occasionally needs updating.
I would recommend against that functionality (in fact, I think I've argued on p5p for removing that possibility from Internals::SvREADONLY. Most read-only values in perl are depending on staying read-only for correct operation. Leon
Subject: Re: [rt.cpan.org #111169] Comparison to Const::Fast?
Date: Thu, 14 Jan 2016 23:56:06 +0000
To: Leon Timmermans via RT <bug-Readonly-Tiny [...] rt.cpan.org>
From: Ben Morrow <ben [...] morrow.me.uk>
Leon Timmermans via RT <bug-Readonly-Tiny@rt.cpan.org> wrote: Show quoted text
> Queue: Readonly-Tiny > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=111169 > > > On Wed Jan 13 17:11:12 2016, ben@morrow.me.uk wrote:
> > 1. It does not perform an assignment; it returns a readonly structure. > > For the situations where I wanted it, this is more useful; in > > particular, I had a bug where a Moo lazy build method was building a > > structure that was supposed to be constant, and some other part of the > > program was accidentally changing it. For a build method this calling > > convention is more useful. I have also used it to assign a ro value to a > > 'state' variable, which is impossible with C::F or Readonly.
> > Sounds entirely reasonable to me. In Const::Fast I tried to make a > drop-in replacement for Readonly, it's not my first choice of > interface either.
Yup, I thought that was the case. I can see why Readonly had to have that interface, given a 5.6 implementation, but it's not a good one. Show quoted text
> > 2. It does not attempt to clone deep structures. C::F not only clones > > the assigned structure (...sometimes), it makes multiple copies of any > > internal cross-references, turning the whole structure into a plain > > tree. This is not always useful, and, IMHO, not part of the job of a > > 'readonly' module.
> > Cloning deep structures is because it may share a part of the graph > with something else that shouldn't be read-only. Breaking internal > cross-references is unintentional and I consider that a bug.
Hmm... I tend to assume that if I asked for something to be made readonly, I meant it, and if it points to something that shouldn't have been, that's my fault. I have been considering some sort of selector function interface, but identifying where we are in the structure in a sensible fashion isn't straightforward, and I haven't needed the functionality, so I haven't bothered. Show quoted text
> > 3. It has a readwrite function; I was not sure about including this, > > given its potential danger, but it is useful in cases like a shared > > cache structure, that should normally be readonly to catch accidental > > modification, but which occasionally needs updating.
> > I would recommend against that functionality (in fact, I think I've > argued on p5p for removing that possibility from > Internals::SvREADONLY. Most read-only values in perl are depending on > staying read-only for correct operation.
There are strong warnings in the documentation against using it carelessly, and an at least minimal non-foot-shooting check against PL_sv_{undef,yes,no}. Also, recent versions of perl seem to have a separate core-only readonly flag, which can't be unset from Perl. Ben