List Info

Thread: The Strict trap




The Strict trap
user name
2007-04-16 09:07:38
Recently one of my trainees was bitten by the Strict trap.
You know,
when you "use Strict" on a platform that has
case-insensitive file
names nothing seems to happen. No error messages, but strict
is not
enabled either.

In the past several discussions have been spent on how to
solve this
problem, and AFAIK all potential solutions were rejected
since they
could in theory break some program some where some time.

Fortunately, the situation with 5.10 is different. Now we
have "use
feature" and this can be used to introduce changes that
would
otherwise be breaking compatibility.

So, for the sake of sanity, lets add a something to 5.10
that prevents
old and new users to ever fall in the Strict trap.

Thanks for your attention,

-- Johan

Re: The Strict trap
user name
2007-04-16 09:24:10
On 16/04/07, Johan Vromans <jvromanssquirrel.nl> wrote:
> Recently one of my trainees was bitten by the Strict
trap. You know,
> when you "use Strict" on a platform that has
case-insensitive file
> names nothing seems to happen. No error messages, but
strict is not
> enabled either.
>
> In the past several discussions have been spent on how
to solve this
> problem, and AFAIK all potential solutions were
rejected since they
> could in theory break some program some where some
time.
>
> Fortunately, the situation with 5.10 is different. Now
we have "use
> feature" and this can be used to introduce changes
that would
> otherwise be breaking compatibility.
>
> So, for the sake of sanity, lets add a something to
5.10 that prevents
> old and new users to ever fall in the Strict trap.

What solution would you suggest ?

I'll quote the comment in op.c:

    /* The "did you use incorrect case?" warning
used to be here.
     * The problem is that on case-insensitive filesystems
one
     * might get false positives for "use" (and
"require"):
     * "use Strict" or "require CARP"
will work.  This causes
     * portability problems for the script: in case-strict
     * filesystems the script will stop working.

(and also as you pointed out strictures weren't enabled
anyway.)

     * The "incorrect case" warning checked
whether "use Foo"
     * imported "Foo" to your namespace, but that
is wrong, too:
     * there is no requirement nor promise in the language
that
     * a Foo.pm should or would contain anything in package
"Foo".

This remark is true. I've met this situation several times.
So I would
tend to think that the warning would be annoying in those
few cases.

One of the roots of the problem is that calling import() or
unimport()
never fails -- it will never raise a "Can't locate
object method"
error. I'm not sure whether we can change this. (and I don't
want to
start thinking about UNIVERSAL::import())

     * There is very little Configure-wise that can be done,
either:
     * the case-sensitivity of the build filesystem of Perl
does not
     * help in guessing the case-sensitivity of the runtime
environment.
     */

Re: The Strict trap
user name
2007-04-16 09:26:39
On Apr 16, 2007, at 9:07 AM, Johan Vromans wrote:

> Recently one of my trainees was bitten by the Strict
trap. You know,
> when you "use Strict" on a platform that has
case-insensitive file
> names nothing seems to happen. No error messages, but
strict is not
> enabled either.

I wouldn't mind having it complain that the pragma could not
be  
found, but doing some sort of DW-some-people-M just seems
wrong-headed.

It also prevents someone from actually intentionally having
Strict.pm  
on a case-sensitive filesystem, and would break things for
those that  
do.

--
Andy Lester => andypetdance.com => www.petdance.com =>
AIM:petdance





Re: The Strict trap
user name
2007-04-16 09:29:13
On Mon, Apr 16, 2007 at 04:24:10PM +0200, Rafael
Garcia-Suarez wrote:

> What solution would you suggest ?
> 
> I'll quote the comment in op.c:
> 
>    /* The "did you use incorrect case?"
warning used to be here.
>     * The problem is that on case-insensitive
filesystems one
>     * might get false positives for "use"
(and "require"):
>     * "use Strict" or "require
CARP" will work.  This causes
>     * portability problems for the script: in
case-strict
>     * filesystems the script will stop working.
> 
> (and also as you pointed out strictures weren't enabled
anyway.)
> 
>     * The "incorrect case" warning checked
whether "use Foo"
>     * imported "Foo" to your namespace, but
that is wrong, too:
>     * there is no requirement nor promise in the
language that
>     * a Foo.pm should or would contain anything in
package "Foo".
> 
> This remark is true. I've met this situation several
times. So I would
> tend to think that the warning would be annoying in
those few cases.

Although we could say that *pragmata* must add something to
their namespace.

Nicholas Clark

Re: The Strict trap
user name
2007-04-16 10:24:50
At 4:12 PM +0200 4/16/07, Johan Vromans wrote:
>Recently one of my trainees was bitten by the Strict
trap. You know,
>when you "use Strict" on a platform that has
case-insensitive file
>names nothing seems to happen. No error messages, but
strict is not
>enabled either.

And this extends to *any* module that has an
"import" function.


>In the past several discussions have been spent on how
to solve this
>problem, and AFAIK all potential solutions were rejected
since they
>could in theory break some program some where some
time.
>
>Fortunately, the situation with 5.10 is different. Now
we have "use
>feature" and this can be used to introduce changes
that would
>otherwise be breaking compatibility.
>
>So, for the sake of sanity, lets add a something to 5.10
that prevents
>old and new users to ever fall in the Strict trap.

If anything, I would go for something like:

  use feature qw(StrictCase);

or something like that, and focus on the case sensitivity,
rather 
than the specific problem that "use Strict"
causes.



Just my 2c  


Liz

Re: The Strict trap
user name
2007-04-16 11:17:54
On Mon, Apr 16, 2007 at 04:07:38PM +0200, Johan Vromans
wrote:
> Recently one of my trainees was bitten by the Strict
trap. You know,
> when you "use Strict" on a platform that has
case-insensitive file
> names nothing seems to happen. No error messages, but
strict is not
> enabled either.
> 
> In the past several discussions have been spent on how
to solve this
> problem, and AFAIK all potential solutions were
rejected since they
> could in theory break some program some where some
time.
> 
> Fortunately, the situation with 5.10 is different. Now
we have "use
> feature" and this can be used to introduce changes
that would
> otherwise be breaking compatibility.
> 
> So, for the sake of sanity, lets add a something to
5.10 that prevents
> old and new users to ever fall in the Strict trap.
> 
> Thanks for your attention,


would adding:

    sub Strict::import {
        warn "You should use 'use strict', not 'use
Strict'n";
    }

to strict.pm catch most of the cases?



Abigail
Re: The Strict trap
user name
2007-04-16 11:50:55
On 4/16/07, Abigail <abigailabigail.be> wrote:
> On Mon, Apr 16, 2007 at 04:07:38PM +0200, Johan Vromans
wrote:
> > Recently one of my trainees was bitten by the
Strict trap. You know,
> > when you "use Strict" on a platform that
has case-insensitive file
> > names nothing seems to happen. No error messages,
but strict is not
> > enabled either.
> >
> > In the past several discussions have been spent on
how to solve this
> > problem, and AFAIK all potential solutions were
rejected since they
> > could in theory break some program some where some
time.
> >
> > Fortunately, the situation with 5.10 is different.
Now we have "use
> > feature" and this can be used to introduce
changes that would
> > otherwise be breaking compatibility.
> >
> > So, for the sake of sanity, lets add a something
to 5.10 that prevents
> > old and new users to ever fall in the Strict
trap.
> >
> > Thanks for your attention,
>
>
> would adding:
>
>     sub Strict::import {
>         warn "You should use 'use strict', not
'use Strict'n";
>     }
>
> to strict.pm catch most of the cases?

That's interesting but it doesn't warn a person off from
getting case
wrong. We see this all time with newbies who just can't seem
to figure
out how to punctuate their perl code. I suppose they either
figure it
out soon or just get frustrated and leave to do something
else.

I'd rather have strict.pm warn off the entire behavior. I
think I'd
also be happy having Perl::Critic do this especially in the
web
interface at perlcritic.org. Maybe then sites like perlmonks
can be
hooked to have semi-automatic criticism.

I'm just reminded that not all language issues need to be
addressed
directly in the perl core.

Josh

Re: The Strict trap
user name
2007-04-16 11:52:34
On Apr 16, 2007, at 11:50 AM, Joshua ben Jore wrote:

> I'm just reminded that not all language issues need to
be addressed
> directly in the perl core.

jjore++  I think that needs to be a p5p mantra.

--
Andy Lester => andypetdance.com => www.petdance.com =>
AIM:petdance





Re: The Strict trap
user name
2007-04-16 12:10:23
Abigail <abigailabigail.be> writes:

> would adding:
>
>     sub Strict::import {
>         warn "You should use 'use strict', not
'use Strict'n";
>     }
>
> to strict.pm catch most of the cases?

Maybe. In any case, it should be croak, not warn, since it
is a fatal
error. 

-- Johan

Re: The Strict trap
user name
2007-04-16 12:35:32
"Rafael Garcia-Suarez" <rgarciasuarezgmail.com> writes:

> What solution would you suggest ?
> I'll quote the comment in op.c:
> [...]

I think any solution that is sufficiently generic will have
at least
as sufficient drawbacks. 

When you use a module or pragma and bypass its import by
miscasing the
name, you'll run into troubles sooner or later. Missing
methods or
packages or something alike.

However, the strict and warnings pragmas are different in
that if you
bypass the import, they just don't work and nothing,
NOTHING!, will
tell you that you missed something.

My solution would be to add a couple of lines of code to
strict.pm and
warnings.pm, that use 'caller' to find out whether the
module is used
by the right name, and if not, bail out with a fatal error.

I cannot think of any existing program that would fail on
that.

-- Johan


[1-10] [11-20] [21-25]

about | contact  Other archives ( Real Estate discussion Medical topics )