http://qs321.pair.com?node_id=11123762


in reply to Backdating strict

If all that was required was to add the line use strict; to the top of your program, you would do it without asking our advice. Doing this, is going to create a huge number of error messages most of which refer to undeclared variables. You could declare these variables at the top of your file until all of these messages are satisfied. That would defeat the purpose of the change. It is unlikely that it would be of any help to anyone. Rethinking the scope requirements of every variable and declaring them appropriately is an error prone task that is probably more work than you are willing to take on. That only fixes "strict vars". If your code violates other restrictions, you could have much bigger problems. I recommend that all new code that you add should conform to strict, but the payback for fixing existing code is not worth the effort required.
Bill

Replies are listed 'Best First'.
Re^2: Backdating strict
by eyepopslikeamosquito (Archbishop) on Nov 18, 2020 at 23:45 UTC

    You may well be right - and I see the redoubtable LanX agrees.

    It depends though on how the original code was written, especially with regard to variable scope. If the original code follows the four simple rules in the Encapsulation section at On Coding Standards and Code Reviews, namely:

    1. Avoid non-const global variables.
    2. Minimize the scope of variables, pragmas, etc..
    3. Minimize the visibility of variables.
    4. Don't overload variables with multiple meanings.
    you might be able to make the code strict-safe quicker than you think. Especially if it's already partitioned into modules with a unit test for each module.

    To prove my point, I remember once coming back to a large module I'd originally written, only to fall off my chair when I noticed some clown had commented out the use strict line at the top of the file! Without a comment to explain why. BTW, On Commenting Out 'use strict;' shows I'm not alone in being scarred for life by this unpleasant experience.

    Anyways, after picking myself up off the floor, I was pleasantly surprised to quickly repair this unfortunate act of code vandalism by restoring the use strict line and making only minor adjustments to the code. Admittedly, having the bulk of the code already strict-safe and having a unit test for the module certainly helped.