Fellow monks,

Forgive me, for I have sinned...

I've started programming when I was 7 years old.. My dad bought a Commodore 64 back in the day, and I fell in love with BASIC programming. I evolved my programming over the years into many languages, Turbo Basic, Turbo Pascal, Turbo C, Borland C++, Delphi, Clarion, VB, until I eventually decided to settle on Perl.

All the professionals have always chastised me for not using strict in any of my code, and I've always been able to tell them that it's not necessary... "My code is working, I've tested it, it's running fine... Go away!" and for the most part, my scripts did work fine.

Then something happened... I decided to write my first Perl modules.. After reading a few bits of documentation, I managed to get my first modules uploaded onto CPAN. Granted it took a few versions to work out exactly what the Makefile.PL script was supposed to look like, but I eventually got there.

The writing of the modules had to have strict in them. Why ? Because the folks that would be using the modules would be stricting, hence I couldn't have a module that would break other applications.

Then something happened. Strict forced me to be a better programmer. Some of my code started breaking, because I had the dirty habbit of declaring a global variable in the main program, and simply reusing that same variable in another do'ed file. Now my code started breaking, but with good reason, and I started to see the light.

In a previous occurence, I played with mod_perl in Apache, and was quite surprised that I can access my perl script, it would work perfectly, until I hit the refresh button on my web browser, and things would break... WTF? The code is fine, of course it is, but the memory variables are all over the place, so no wonder things would end up in a steaming pile of crap.

So in short, I'm now converted... I promise that from this day forward, any script that comes in contact with me will have use strict; added to the top. I will tell all that cross my path that this is how it should be. It makes you a better coder, it makes your code better, and forces the universe to be aligned with your goals. use strict || die;

Replies are listed 'Best First'.
Re: My confession - I'm now strict-ing...
by JavaFan (Canon) on Jan 25, 2010 at 08:16 UTC
    The writing of the modules had to have strict in them. Why ? Because the folks that would be using the modules would be stricting, hence I couldn't have a module that would break other applications.
    Huh? Strictness is lexically scoped - any module that uses strict can use a module that doesn't use strict. It won't break. In particular, any code that runs fine with strict, will continue to run fine, and in exactly the same way, if you remove the line use strict;.
    Some of my code started breaking, because I had the dirty habbit of declaring a global variable in the main program, and simply reusing that same variable in another do'ed file.
    Ah, yes, usually not a good idea. But use strict; won't prevent you from using global variables; it doesn't even prevent you from using cross-scope variables. Nor does using lexical variables implies you are using strict.
    I promise that from this day forward, any script that comes in contact with me will have use strict; added to the top.
    Yes, and? It's a popular myth that using use strict; makes you a better coder, or improves your code. It doesn't. Your stories implies that your code improves by using lexical variables instead of package variables. That's the important lesson. Not the strict. The latter only helps you to think more carefully when using package variables.
      In particular, any code that runs fine with strict, will continue to run fine, and in exactly the same way, if you remove the line use strict;.

      Most of the time, yes. But not always.

      use strict 'refs'; has a run-time effect. There can be programs that rely on symbolic references throwing an error. A program can rely on such behaviour.

      use 5.010; sub ok { # remove the "use strict;" and try again... use strict; local $@; eval { $_[0]->[0]; 1 }; } say ok('foo');

      It is unlikely that this code appears like this in production somewhere, but it can very well be hidden somewhere less obvious.

      Perl 6 - links to (nearly) everything that is Perl 6.
      The latter only helps you to think more carefully when using package variables.

      And thus makes your code better. use strict; doesn't improve the code, it forces (well, unless you really resist) YOU to improve your code.

      It's like a warning sign. The piece of plastic or tin with some writing doesn't make the appliance safer in itself, it helps you think more carefully before doing something dangerous. And thus actually does make it safer.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

        And thus makes your code better. use strict; doesn't improve the code, it forces (well, unless you really resist) YOU to improve your code.
        Actually, it doesn't force you. When it comes the variables, the easy way out is just sticking 'our' in front of all the undeclared variables, or my()ing them on the top level. It does satisfy strict.

        I really hope people don't think that's an improvement of the quality of the code.

        Note, I'm not saying one shouldn't use strict. But strict isn't a silver bullet, and its presence on itself in code doesn't mean much.

Re: My confession - I'm now strict-ing...
by locked_user sundialsvc4 (Abbot) on Jan 29, 2010 at 18:21 UTC

    I am always of the opinion that “finding annoying bugs (that a computer is able to catch) is what a digital computer is for.” That lets me focus my attention on the truly interesting and bewildering bugs. :-D