-
Notifications
You must be signed in to change notification settings - Fork 582
[feature] strict and warnings optional extensions #18543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
An excellent idea. Over the years I have thought up a few things I thought ought to be For example, my own https://metacpan.org/pod/release/PEVANS/stringification-0.01_004/lib/stringification.pm Other thoughts we've had over the years are that maybe |
Cross-posted to perl5-porters: https://www.nntp.perl.org/group/perl.perl5.porters/2021/02/msg259029.html |
use strict 'direct' use strict 'filehandles'; is natural for me rather than "no indirect" and no feature 'bareword::filehandles' because this is things related to syntax. |
This idea also recently discussed on perl5-porters@: https://www.nntp.perl.org/group/perl.perl5.porters/2021/11/msg261932.html |
I feel like ok my_function(), "my_function() works"; This doesn’t work if indirect object syntax is prohibited in code. At least I don’t want that. |
I hope this is not out of scope for this issue: I currently have the problem that my app’s base module enables If the
|
That would unfortunately be an incompatible change, and I would consider it out of scope for this request. This request requires that all existing behavior is maintained, only a new category is added, and warnings continue to be put in the appropriate category to behave as expected. It's up to modules like Moose to preserve the current status of warnings if they desire so. |
Since they were introduced in early Perl 5,
strict
andwarnings
have enabled the equivalent ofall
when used in the recommendeduse strict;
anduse warnings;
forms. There have occasionally been ideas of additional behavior that would make sense for these pragmas to enable, but without enabling them in the massive amount of existing code which currently enableall
implicitly or explicitly. So I propose that mechanisms be added for "optional" strictures and warnings, which are not enabled byuse strict; use warnings;
.strict has three subpragmas:
vars
,refs
, andsubs
. There is noall
category, but a bareuse strict;
enables these three items. So to add an optional stricture, we would need a mechanism to add a subpragma which is not enabled by a bareuse strict;
, and users could then simplyuse strict 'whatever';
to opt-in to the stricture for that scope. A flag touse strict
which would enable these additional strictures could be considered, but I do not think it would be a good idea since such a flag would effectively be restricted to whatever it enables the first time it's added.warnings has hundreds of warning categories organized in a few classifications, as described in perldiag.
(S)
and(D)
class warnings are enabled by default - they are considered severe enough that all code should be subject to them, unless explicitly disabled.(W)
class warnings are not enabled by default, but are enabled when underuse warnings 'all';
, which is the same asuse warnings;
.There is no policy against adding new warnings to these classifications at any time - but there is an expectation for the warnings to be reasonable for the classification they're added to, so as not to cause grief for users who expected certain behavior.
So to add "optional warnings", we would need a new optional warnings classification
(O)
which is not enabled byuse warnings 'all';
oruse warnings;
. Yes, this makes the 'all' category name misleading, but I assert that this doesn't really matter, because very few people actually spell it out. An 'optional' category name and a way to enable it in addition to 'all' could be reasonable for users who really want all possible warnings, but this shouldn't necessarily be encouraged, because such 'optional' warnings would be limited to those which are deemed too niche for the userbase at large.I am purposely describing only the user-facing API design, as the implementation details are outside my expertise, but an important component of making this happen.
The text was updated successfully, but these errors were encountered: