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
perlstyle - Modernize description of strict/warnings and usage of open #17138
Comments
From @Grinnzperlstyle contains some outdated advice for strict and warnings usage, and -Dan (Perl) |
From @GrinnzPatches attached. |
From @Grinnz0001-Rewrite-paragraph-on-using-strict-and-warnings.patchFrom 2581245cb372b10fde1bfc7919089096077a9bbd Mon Sep 17 00:00:00 2001
From: Dan Book <grinnz@grinnz.com>
Date: Wed, 28 Aug 2019 18:34:51 -0400
Subject: [PATCH 1/2] Rewrite paragraph on using strict and warnings
---
pod/perlstyle.pod | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/pod/perlstyle.pod b/pod/perlstyle.pod
index 5c2534581e..1f64b9ec3c 100644
--- a/pod/perlstyle.pod
+++ b/pod/perlstyle.pod
@@ -8,12 +8,13 @@ Each programmer will, of course, have his or her own preferences in
regards to formatting, but there are some general guidelines that will
make your programs easier to read, understand, and maintain.
-The most important thing is to run your programs under the B<-w>
-flag at all times. You may turn it off explicitly for particular
-portions of code via the C<no warnings> pragma or the C<$^W> variable
-if you must. You should also always run under C<use strict> or know the
-reason why not. The C<use sigtrap> and even C<use diagnostics> pragmas
-may also prove useful.
+The most important thing is to use L<strict> and L<warnings> in all your
+code or know the reason why not to. You may turn them off explicitly for
+particular portions of code via C<no warnings> or C<no strict>, and this
+can be limited to the specific warnings or strict features you wish to
+disable. The B<-w> flag and C<$^W> variable should not be used for this
+purpose since they can affect code you use but did not write, such as
+modules from core or CPAN.
Regarding aesthetics of code lay out, about the only thing Larry
cares strongly about is that the closing curly bracket of
@@ -262,7 +263,7 @@ Line up your transliterations when it makes sense:
Think about reusability. Why waste brainpower on a one-shot when you
might want to do something like it again? Consider generalizing your
code. Consider writing a module or object class. Consider making your
-code run cleanly with C<use strict> and C<use warnings> (or B<-w>) in
+code run cleanly with C<use strict> and C<use warnings> in
effect. Consider giving away your code. Consider changing your whole
world view. Consider... oh, never mind.
--
2.20.1
|
From @Grinnz0002-Avoid-2-arg-open-and-bareword-handles.patchFrom 8ec056ea33278fadc40af22b862b1e43ba4c8a32 Mon Sep 17 00:00:00 2001
From: Dan Book <grinnz@grinnz.com>
Date: Wed, 28 Aug 2019 18:41:34 -0400
Subject: [PATCH 2/2] Avoid 2 arg open and bareword handles
---
pod/perlstyle.pod | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pod/perlstyle.pod b/pod/perlstyle.pod
index 1f64b9ec3c..adc0f0d69f 100644
--- a/pod/perlstyle.pod
+++ b/pod/perlstyle.pod
@@ -103,11 +103,11 @@ you I<SHOULD> do it that way. Perl is designed to give you several
ways to do anything, so consider picking the most readable one. For
instance
- open(FOO,$foo) || die "Can't open $foo: $!";
+ open(my $fh, '<', $foo) || die "Can't open $foo: $!";
is better than
- die "Can't open $foo: $!" unless open(FOO,$foo);
+ die "Can't open $foo: $!" unless open(my $fh, '<', $foo);
because the second way hides the main point of the statement in a
modifier. On the other hand
@@ -249,7 +249,7 @@ system call and arguments were, and (VERY IMPORTANT) should contain the
standard system error message for what went wrong. Here's a simple but
sufficient example:
- opendir(D, $dir) or die "can't opendir $dir: $!";
+ opendir(my $dh, $dir) or die "can't opendir $dir: $!";
=item *
--
2.20.1
|
From @TuxOn Wed, 28 Aug 2019 15:48:38 -0700, "Dan Book via RT"
+1 from me. I like them -- |
The RT System itself - Status changed from 'new' to 'open' |
From @khwilliamson |
@khwilliamson - Status changed from 'open' to 'pending release' |
Migrated from rt.perl.org#134387 (status was 'pending release')
Searchable as RT134387$
The text was updated successfully, but these errors were encountered: