Grokbase
x

Re: [perl #70043] Re: [Sysadmins] Perl allows non-sensical operations on reference converted to an integer

View PostFlat  Thread  Threaded | < Prev - Next >
A. Pagaltzis Re: [perl #70043] Re: [Sysadmins] Perl allows non-sensical operations on reference converted to an integer
| +1 vote
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
* George Greer <perl@greerga.m-l.org> [2009-10-27 13:15]:
> I'd perhaps use it as a "no stringify;" (like "no indirect;")

A better name might be something like `no refconv;` (which would
include preventing numeric operations on numified references).

> My favorite stringy-oops has been doing tr// on a list of mixed
> strings/refs, but that gets tracked down pretty quickly.

When working with non-trivially nested data it’s not uncommon to
get a `Can't use string ("HASH(0xdeadbeef)") as a FOO ref`
somewhere, or absurd numbers when you’re calculating some kind of
aggregate, because you accidentally accessed the wrong element
and numified a ref instead of accessing the right scalar, or
tried to deref a scalar instead of accessing the ref you wanted.

And it’s always real tedious to track down where the actual
mistake is in such cases, even when it doesn’t ultimately take
much time. You usually have to try to trace logic that winds
through recursive calls or nested loops, which is a chore whether
you debug with the debugger or with print statements.

It would be much less painful if you could at least optionally
enable a fatal error for implicit ref conversions, for debugging
purposes. That would immediately tell you the “where� half of the
problem, instead of leaving you to painstakingly hunt for it.
Throw a Carp::Always in there and you probably have most of the
data you need to figure out the “why�.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread : [perl #70041] Perl allows non-sensical operations on reference converted to an integer
1)
Kevin Wolf # New Ticket Created by goldstei@ugcs.caltech.edu # Please include the string: [perl #70041] # in...
2)
Kevin Wolf # New Ticket Created by goldstei@ugcs.caltech.edu # Please include the string: [perl #70043] # in...
3)
A. Pagaltzis Only in semantic nitpicking in that it works as designed. As far as I’m concerned that design is...
4)
David Golden te: To me, it seems consistent with the idea "use strict 'refs'" -- if strictures are on,...
5)
Nicholas Clark Which breaks existing code that uses strict, and the idiom of using the stringification of...
6)
David Golden That "idiom" is an accident waiting to happen because of overloading. It should at least warn. But...
7)
Abigail What overloading? ;-) *I* know when my code uses overloading. It usually doesn't. It shouldn't warn...
8)
A. Pagaltzis What does that have to do with anything? We’re talking about implicit conversions of references,...
9)
Paul Johnson And would also reduce the enjoyment we all get at seeing HASH(0x81531d8) on a web page somewhere.
10)
Paul LeoNerd Evans --Sig_/nH1LMUAKyQOos/q7FMl+c3S Content-Type: text/plain; charset=US-ASCII...
11)
Abigail I use often stringified references. Either by printing them (debugging tool), or as hash keys. If I...
12)
David Golden Fortunately, you'd still be able to do so in pre-5.10 perl. :-) Making reference stringification a...
13)
Abigail Ah, but perhaps $hash {refaddr $ref} should warn as well, because it's a disaster waiting to...
14)
Nicholas Clark If "your" module loading is borked, we don't support "you". Nicholas Clark
15)
David Golden Module loading in general. Otherwise, 'use Scalar::Util qw/refaddr/'. The question is whether...
16)
George Greer Content-Type: TEXT/PLAIN; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT I'd perhaps...
17)
A. Pagaltzis A better name might be something like `no refconv;` (which would include preventing numeric...
18)
Abigail That's easy, no additional support needed: package UNIVERSAL; use overload '""' => sub {die}; use...
19)
A. Pagaltzis $ perl -E'{package UNIVERSAL; use overload q[""] => sub {die}, "0+" => sub{die}} say \$_'...
20)
David Nicol Given an alternate universe where all Perl types are "Magic" and look up all of their operations in...
21)
Ricardo SIGNES I believe, but have not Googled, that MJD proposed this some time ago as C< no strict 'deref' >.
22)
Rafael Garcia-Suarez 2009/10/27 Ricardo Signes <perl.p5p@rjbs.manxome.org>: No, he proposed it as C<use strict 'refs'> :...
23)
demerphq 2009/10/27 Rafael Garcia-Suarez <rgs@consttype.org>: Have we fixed this is new perls? That is made...
24)
Abigail I would prefer a new pragma as well, but I don't really understand your argument. After all, if...
25)
Rafael Garcia-Suarez 2009/10/27 Abigail <abigail@abigail.be>: Not exactly : to use a new pragma, you have to modify your...
26)
A. Pagaltzis I wouldn’t, but I would strictly oppose conflating them. I can easily imagine good uses for no...
27)
Paul Johnson I seem to recall that the last time someone wanted a new stricture (FSVO last) there was general...
28)
John In which case somthing like use warnings FATAL => qw(refconv); would be more appropriate.
spacer
View PostFlat  Thread  Threaded | < Prev - Next >