Skip to content
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

Closed
p5pRT opened this issue Aug 28, 2019 · 8 comments
Closed

perlstyle - Modernize description of strict/warnings and usage of open #17138

p5pRT opened this issue Aug 28, 2019 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 28, 2019

Migrated from rt.perl.org#134387 (status was 'pending release')

Searchable as RT134387$

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2019

From @Grinnz

perlstyle contains some outdated advice for strict and warnings usage, and
2-arg opens with bareword filehandles. Patches to be attached.

-Dan

(Perl)

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2019

From @Grinnz

Patches attached.

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2019

From @Grinnz

0001-Rewrite-paragraph-on-using-strict-and-warnings.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Aug 28, 2019

From @Grinnz

0002-Avoid-2-arg-open-and-bareword-handles.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2019

From @Tux

On Wed, 28 Aug 2019 15​:48​:38 -0700, "Dan Book via RT"
<perlbug-followup@​perl.org> wrote​:

Patches attached.

+1 from me. I like them

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.31 porting perl5 on HP-UX, AIX, and Linux
https​://useplaintext.email https://tux.nl  http​://www.test-smoke.org
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Aug 29, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2019

From @khwilliamson

Thanks, applied as
3f1e98f
3b2e562
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Aug 30, 2019

@khwilliamson - Status changed from 'open' to 'pending release'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant