Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Learn from what's out there!

by DentArthurDent (Monk)
on Oct 16, 2003 at 12:57 UTC ( #299728=note: print w/ replies, xml ) Need Help??


in reply to use sloppy ;-)

In most other compiled languages, you get all errors and some number of warnings at compile time, and then you have the ability to vary the number of warnings.

As I understand things (never used it), strict causes things that wouldn't otherwise have been errors to be errors and is recommended. I think this is a bad idea. Better to have anything that is that dangerous always be an error. Ask yourself: is it an error or isn't it?

Warnings on the other hand, should have variable levels. Pick a few things that generally are bad bad errors but might be ok and use that as a starting point, then leave it up to the user to turn them all on or all off.

Can you tell I code more in C than Perl? :-)

----
May your tongue cleave to the roof of your mouth with the force of a thousand caramels.


Comment on Learn from what's out there!
Re: Learn from what's out there!
by Abigail-II (Bishop) on Oct 16, 2003 at 13:16 UTC
    All use strict does is make the Perl compiler more like a C compiler: picky. I'd expect people with a C background to embrace 'strict' quicker than people coming from a shell background (or people with no background in programming at all).

    Abigail

Re: Learn from what's out there!
by dragonchild (Archbishop) on Oct 16, 2003 at 13:38 UTC
    strict deals with things that almost always aren't what you want to do. But, strict robs the ability of the experienced developer to do cool things. This is why no strict; and no warnings 'blah' are there. All my Exporter modules have the following at the top:
    package Something::Or::Other; use strict; use warnings no warnings 'once'; # Stuff here 1;

    The 'once' item is one I don't want in a values repository. But, I don't use the no warnings 'once' item in my scripts because I should be using all my variables more than once. (If it's a repository, it should be in an Exporter module.)

    The same goes double with strict. The only strict item I ever turn off is 'refs', but I turn it off a lot, in specific situations when I really do have to use soft references. But, I know why I'm using soft references and I am planning on using soft references. Everywhere else, I'm too lazy to keep track, so I want the compiler to keep track for me, so I turn strict on.

    Soft references are dangerous in every situation ... just in most of them. So, if they were always errors, a lot of code wouldn't work. (Like, the code in Exporter, the most commonly used non-pragma module in Perl.)

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      So is the point of strict, then, to take the rope out of the hands of a programmer so that they can't hang themselves? I guess there's a place for that. I withdraw my objection. :)
      ----
      May your tongue cleave to the roof of your mouth with the force of a thousand caramels.
        The point is to provide automated rope-removal, should the programmer want it. It's all in the spirit of TIMTOWDI.

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Learn from what's out there!
by hardburn (Abbot) on Oct 16, 2003 at 14:19 UTC

    Better to have anything that is that dangerous always be an error. Ask yourself: is it an error or isn't it?

    This code is an error under strict 'refs':

    foreach my $field (qw( foo bar baz)) { *$field = sub { my $self = shift; $self->{$field} = shift if @_; $self->{$field}; }; }

    This is an incredibly great way to create accessors/mutators for an object in the simplist and most common case. It makes it easy to create new accessors/mutators, and is very memory-efficent (since there is actually only one subroutine in memory that handles many different cases).

    OTOH, the following also won't work under strict 'refs':

    use CGI qw(:all); my @names = param(); foreach my $name (@names) { $$name = param($name); }

    The fact that the above doesn't work under strict 'refs' is a good thing. It would allow any parameters passed to the CGI to clobber the values of existing scalars in the namespace. (This is based on a real example I saw in a SoPW a while back by a well-meaning but obviously inexperianced CGI programmer).

    Thus, a new user should always use strict to catch potential errors, but an experianced coder will know when it's OK to shut it off.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    :(){ :|:&};:

    Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://299728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2014-07-23 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (150 votes), past polls