develooper Front page | perl.perl5.porters | Postings from September 2019

[perl #134452] ref should trigger warnings and doc needs work

Thread Previous | Thread Next
Dan Book via RT
September 27, 2019 22:25
[perl #134452] ref should trigger warnings and doc needs work
Message ID:
On Thu, 26 Sep 2019 18:20:45 -0700, wrote:
> Reading this I think ref should warn 'deprecated'.
> Ref should warn 'imprecision' on any blessed object.
> At best, it seems that ref should only be used when dealing with
> an unblessed object.  That should be made clear.  The documentation
> language is poor as the antecedent to "that" in "don't use that" is
> distant.
> But beyond clarifying this language, a clear "Using ref is now
> considered bad practice." should be at the top of the page.

I disagree with this assessment. ref is a highly useful lightweight function for distinguishing between a reference and a non-reference, or determining the reference type when you are already sure the reference is not blessed, or if you are willing to live with breakage when someone decided a class named ARRAY was a good idea. The caveat that it may also return a class name sometimes, is unimportant for a large percentage of use cases.

reftype is in fact not useful for blessed references either, because a blessed reference should only be used via its documented interface (which may include internals or overloads, but usually doesn't). If you want to account for blessed references, you should always start with Scalar::Util::blessed.

> Note also that the reference to Scalar::Util::reftype is damaged by
> the lack of rigor in its documentation.  Is a 'basic type' the
> same as your 'builtin' type?  Very likely I'd guess, but I would
> not want to guess that all 11 builtin types are handled by
> Scalar::Util.

This could be reported or patched in Scalar::Util which is maintained on CPAN. And yes, they do refer to the same types.


via perlbug:  queue: perl5 status: new

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About