Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 31977
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.088
Fixed in: (no value)



Subject: "Integer with leading zeros" exceptions for chmod()?
$ echo "use strict; chmod 0644, $file" | perlcritic Integer with leading zeros at line 1, column 20. See page 58 of PBP. (Severity: 5) Is it really bad practice to use the 0xxx form with chmod, the natural Unix form of mode expression? Can an exception be made for chmod 0xxx so that it's accepted or at least at a reduced severity? Interestingly, it ignores the real mistakes: $ echo "use strict; chmod q[0644], $file" | perlcritic source OK $ echo "use strict; chmod 644, $file" | perlcritic source OK So really chmod needs "Integer *without* leading zeros" and "mode as string" critics.
Similar issues with dbmopen, mkdir and umask. I'd also throw in the bitwise operators at least for the "it's ok to use 0xxx" part.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Fri, 28 Dec 2007 21:06:06 -0800 (PST)
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeffrey_thalhammer [...] yahoo.com>
We can do that. Do you think it should be a universal exemption, or something that you have to ask for in your perlcriticrc file? -Jeff
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Fri, 28 Dec 2007 22:38:49 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Jeffrey Thalhammer via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=31977 > > > We can do that. Do you think it should be a universal exemption, or something that you have to ask for in your perlcriticrc file?
Universal, especially if combined with the aforementioned proper critiques of the uses of masks (ie. "integer without leading zero" and "string used for octal mode"). -- 'All anyone gets in a mirror is themselves,' she said. 'But what you gets in a good gumbo is everything.' -- "Witches Abroad" by Terry Prachett
From: ELLIOTJS [...] cpan.org
On Fri Dec 28 21:45:37 2007, MSCHWERN wrote: Show quoted text
> I'd also throw in the bitwise operators at least for the "it's ok to use > 0xxx" part.
I'd hope I wouldn't see such usage anywhere, but that may be personal preference. The only place I'd personally accept octal is in relation to Unix permissions.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 08:26:41 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
ELLIOTJS via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=31977 > > > On Fri Dec 28 21:45:37 2007, MSCHWERN wrote:
>> I'd also throw in the bitwise operators at least for the "it's ok to use >> 0xxx" part.
> > I'd hope I wouldn't see such usage anywhere, but that may be personal preference. The only > place I'd personally accept octal is in relation to Unix permissions.
To be fair, I haven't run across the bitwise case yet. Everything else I've reported are actual MakeMaker issues (which is now otherwise critic clean). But looking at something like, say, File::chmod: http://search.cpan.org/src/PINYAN/File-chmod-0.32/chmod.pm $VAL |= 0400 if /r/; $VAL |= 0200 if /w/; $VAL |= 0100 if /[xs]/; $VAL |= 04000 if /[sS]/; That's perfectly natural for bitwise ops. If I saw instead: $VAL |= oct 400 if /r/; $VAL |= oct 200 if /w/; $VAL |= oct 100 if /[xs]/; $VAL |= oct 4000 if /[sS]/; I'd question that. I don't think it adds any clarity and instead strays from accepted practice. Kinda makes the brain go "buh?" PBP doesn't actually have anything *against* octal numbers when used properly. It's when you use them improperly, as padding, expecting 007 to be the same as 7. Clearly with bitwise ops and masks you naturally want to be working in octal or binary or hex. Bitwise ops might be esoteric, but they have their place. As much as we like to avoid it as Perl programmers, sometimes you've got to get down to fiddling with individual bits. -- Just call me 'Moron Sugar'. http://www.somethingpositive.net/sp05182002.shtml
From: ELLIOTJS [...] cpan.org
On Sat Dec 29 11:27:27 2007, schwern@pobox.com wrote: Show quoted text
> ELLIOTJS via RT wrote:
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=31977 > > > > > On Fri Dec 28 21:45:37 2007, MSCHWERN wrote:
> >> I'd also throw in the bitwise operators at least for the "it's ok > >> to use 0xxx" part.
> > > > I'd hope I wouldn't see such usage anywhere, but that may be > > personal preference. The only place I'd personally accept octal > > is in relation to Unix permissions.
> > To be fair, I haven't run across the bitwise case yet. Everything > else I've reported are actual MakeMaker issues (which is now > otherwise critic clean). > > But looking at something like, say, File::chmod: > http://search.cpan.org/src/PINYAN/File-chmod-0.32/chmod.pm
[chop] Show quoted text
> That's perfectly natural for bitwise ops. If I saw instead:
[chop] Show quoted text
> I'd question that. I don't think it adds any clarity and instead > strays from accepted practice. Kinda makes the brain go "buh?"
That's a false complaint. Obviously File::chmod is dealing with Unix permissions. The fact that it's using bitwise operators to deal with them is beside the point. Show quoted text
> Clearly with bitwise ops and masks you naturally want to be > working in octal or binary or hex. > > Bitwise ops might be esoteric, but they have their place. As > much as we like to avoid it as Perl programmers, sometimes > you've got to get down to fiddling with individual bits.
Again, you're generalizing my statements. I didn't say anything about not using bitwise operations. I said I don't want octal anywhere other than Unix permissions. Bitwise operations should be done using hex (again with the exception above for things like File::chmod).
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 10:34:00 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
ELLIOTJS via RT wrote: Show quoted text
>> I'd question that. I don't think it adds any clarity and instead >> strays from accepted practice. Kinda makes the brain go "buh?"
> > That's a false complaint. Obviously File::chmod is dealing with Unix permissions. The fact > that it's using bitwise operators to deal with them is beside the point.
My complain is more pragmatic: How does Perl::Critic tell the difference? It can't know that File::chmod is working with unix permissions, all it sees is the bitwise ops. So the exception for "integer without leading zero" should extend to bitwise ops. Show quoted text
>> Clearly with bitwise ops and masks you naturally want to be >> working in octal or binary or hex. >> >> Bitwise ops might be esoteric, but they have their place. As >> much as we like to avoid it as Perl programmers, sometimes >> you've got to get down to fiddling with individual bits.
> > Again, you're generalizing my statements. I didn't say anything about not using bitwise > operations. I said I don't want octal anywhere other than Unix permissions. Bitwise > operations should be done using hex (again with the exception above for things like > File::chmod).
What is the reason for preferring hex? Hex and octal are both base x**2 so it shouldn't really matter for bitwise work. In fact, if you're working in bytes thinking base 8 makes a lot more sense. This is something that Perl::Critic can't really say much about, either is fine and their appropriate use is situational. It does further support the "integer does *not* contain leading zero" critic for bitwise ops indicating someone tried to use a decimal for bitwise ops which, we can agree, is probably wrong. Let's check if we're having a violent agreement. Here's what I'd recommend: *) Leave the "integer with leading zeros" critic in for the general case *) Exempt dbmopen, mkdir, umask and chmod file masks and bitwise operations. For those the warning should be "integer without leading zero" or more clearly "decimal number used with $operator" to warn against the use of a decimal number and "string used with $operator" for a string. # integer with leading zeros $spy = 007; # decimal permissions used with chmod chmod 666, $file; # string mask used with mkdir mkdir $dir, "0755"; # ok chmod 0666, $file; # ok $mode |= 0755; # ok $thing = $num | 0b1001001; # ok $thing = $num & 0xDEADBEEF; # decimal number used with bitwise op $mask |= 755; # string used with bitwise op $mask |= "0755"; -- There will be snacks.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 14:12:04 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <elliotjs [...] cpan.org>
Michael G Schwern via RT wrote: Show quoted text
> My complain is more pragmatic: How does Perl::Critic tell the > difference? It can't know that File::chmod is working with unix > permissions, all it sees is the bitwise ops. > > So the exception for "integer without leading zero" should extend to > bitwise ops.
File::chmod is an exception, not the rule. Show quoted text
> What is the reason for preferring hex? > > Hex and octal are both base x**2 so it shouldn't really matter for > bitwise work. In fact, if you're working in bytes thinking base 8 > makes a lot more sense.
Base 8 is only good if you're thinking strict ASCII, but not bytes, since almost all architectures now use 8 bits. (In a college programming languages course I took there was someone who worked with an architecture with 9 bits per byte, for which it would be appropriate to use octal. But this was close to 20 years ago.) Having a leading "digit" (octit?) that can only be 0 or 1 seems stupid to me. Show quoted text
> It does further support the "integer does *not* contain leading zero" > critic for bitwise ops indicating someone tried to use a decimal for > bitwise ops which, we can agree, is probably wrong.
I can certainly see a separate ProhibitDecimalWithBitwiseOperator policy which would allow binary, octal, or hex being useful. Show quoted text
> Let's check if we're having a violent agreement. Here's what I'd > recommend: > > *) Leave the "integer with leading zeros" critic in for the general > case > > *) Exempt dbmopen, mkdir, umask and chmod file masks and bitwise > operations.
The second to last word in that latter point I disagree with. Again, this may be personal preference. I don't like forms that don't match with bytes. Otherwise, I agree with your statements above. Show quoted text
> For those the warning should be "integer without leading zero" or > more clearly "decimal number used with $operator" to warn against the > use of a decimal number and "string used with $operator" for a > string.
Again, the new separate policy suggestion above.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 15:06:50 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Elliot Shank wrote: Show quoted text
>> It does further support the "integer does *not* contain leading zero" >> critic for bitwise ops indicating someone tried to use a decimal for >> bitwise ops which, we can agree, is probably wrong.
> > I can certainly see a separate ProhibitDecimalWithBitwiseOperator policy > which would allow binary, octal, or hex being useful.
Expressions::ProhibitDecimalWithBitwiseOperator and Expressions::ProhibitStringsWithBitwiseOperator added to TODO list.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 13:32:58 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
ELLIOTJS via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=31977 > > > Michael G Schwern via RT wrote:
>> My complain is more pragmatic: How does Perl::Critic tell the >> difference? It can't know that File::chmod is working with unix >> permissions, all it sees is the bitwise ops. >> >> So the exception for "integer without leading zero" should extend to >> bitwise ops.
> > File::chmod is an exception, not the rule.
I think this can boil down to one simple question: What *exactly* is wrong with using octal in bitwise ops to the point that you'd actively prohibit it? Reading the original PBP on this, the point was to avoid people who mistake 0123 for 123 and think it's just padding. There's nothing actually wrong with octal numbers. Thinking about it further, if you're mistakenly using 0123 on bitwise ops TWO failures have to take place at the user end: 1) They don't realize that 0123 is octal (yet they're doing bitwise math) 2) They're really trying to do bitwise on decimal numbers I find the combination of user failures to be unlikely. What mistake is perlcritic preventing by prohibiting $foo & 0777 ? Show quoted text
>> What is the reason for preferring hex? >> >> Hex and octal are both base x**2 so it shouldn't really matter for >> bitwise work. In fact, if you're working in bytes thinking base 8 >> makes a lot more sense.
> > Base 8 is only good if you're thinking strict ASCII, but not bytes, since almost > all architectures now use 8 bits.
Uhh, aren't we agreeing then? I wasn't thinking ASCII at all, just that each octal digit neatly represents one byte and isn't that handy? Show quoted text
> (In a college programming languages course I took there was someone who worked > with an architecture with 9 bits per byte, for which it would be appropriate
to use octal. Show quoted text
> But this was close to 20 years ago.)
I don't understand how octal is appropriate for 9 bit bytes. Show quoted text
> Having a leading "digit" (octit?) that can only be 0 or 1 seems stupid to me.
Again, I'm sorry, but I don't follow. I will admit, I'm not Mr. Bitwise. Show quoted text
>> It does further support the "integer does *not* contain leading zero" >> critic for bitwise ops indicating someone tried to use a decimal for >> bitwise ops which, we can agree, is probably wrong.
> > I can certainly see a separate ProhibitDecimalWithBitwiseOperator policy which would > allow binary, octal, or hex being useful.
Would that be a separately installed and activated policy? If so, I'm going to continue to slug it out in that perlcritic is misapplying PBP's advice. Show quoted text
>> Let's check if we're having a violent agreement. Here's what I'd >> recommend: >> >> *) Leave the "integer with leading zeros" critic in for the general >> case >> >> *) Exempt dbmopen, mkdir, umask and chmod file masks and bitwise >> operations.
> > The second to last word in that latter point I disagree with.
Ok, we're getting somewhere. Show quoted text
> Again, this may be personal preference. I don't like forms that don't match
with bytes. Again, I don't get it. How does base 8 not match up with 8 bit bytes? For that matter, how does hex? Each digit of hex is two bytes. And, here's the most important question, why does perlcritic have anything to say about this? -- You know what the chain of command is? It's the chain I go get and beat you with 'til you understand who's in ruttin' command here. -- Jayne Cobb, "Firefly"
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 13:37:56 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Immediately after I sent that last reply someone explained the octal / 9 bits thing to me. Now I get it. Even so, given that bitwise ops are commonly used for Unix masks and how highly unlikely it is that using octal digits on bitwise ops is a mistake, I don't see why perlcritic should have an opinion about octal with bitwise ops and just what mistake it's preventing.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 16:47:05 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <elliotjs [...] cpan.org>
Michael G Schwern via RT wrote: Show quoted text
> I think this can boil down to one simple question: What *exactly* is > wrong with using octal in bitwise ops to the point that you'd > actively prohibit it? > > Reading the original PBP on this, the point was to avoid people who > mistake 0123 for 123 and think it's just padding. There's nothing > actually wrong with octal numbers.
To quote: "To avoid this covert transmutation of the numbers, never start a literal integer with zero. Even if you do intend to specify octal numbers, don't use a leading zero, as that may still mislead inattentive future readers of your code." What part of "never" do you not understand? Show quoted text
>>> What is the reason for preferring hex? >>> >>> Hex and octal are both base x**2 so it shouldn't really matter >>> for bitwise work. In fact, if you're working in bytes thinking >>> base 8 makes a lot more sense.
>> >> Base 8 is only good if you're thinking strict ASCII, but not bytes, >> since almost all architectures now use 8 bits.
> > Uhh, aren't we agreeing then? I wasn't thinking ASCII at all, just > that each octal digit neatly represents one byte and isn't that > handy?
No. An octal digit represents three bits. Show quoted text
>> Having a leading "digit" (octit?) that can only be 0 or 1 seems >> stupid to me.
> > Again, I'm sorry, but I don't follow. I will admit, I'm not Mr. > Bitwise.
My bad in not being more specific. For signed values, the most significant octit can only be 0 or 1. For signed values, it's 0 to 3. Show quoted text
>> I can certainly see a separate ProhibitDecimalWithBitwiseOperator >> policy which would allow binary, octal, or hex being useful.
> > Would that be a separately installed and activated policy?
Yup. Show quoted text
>> Again, this may be personal preference. I don't like forms that >> don't match with bytes.
> > Again, I don't get it. How does base 8 not match up with 8 bit > bytes? For that matter, how does hex? Each digit of hex is two > bytes.
Each "hit" represents two nybbles, thus coming together to represent a single byte. Base 8 means that you can represent the values 0-7. This takes three bits, i.e. 07 == 0b111. Thus, after taking 6 bits to represent the least significant part of the byte, you're left with two bits to represent the most significant part, which in octal means the values 0 to 3. The maximum value an unsigned byte can hold: 0b11111111 == 255 == 0377 == 0xff Thus my complaint about using an octal number to represent a byte: the most significant part of the number is restricted to the values 0 to 3, while the other parts go 0 to 7. Show quoted text
> And, here's the most important question, why does perlcritic have > anything to say about this?
Because PBP does.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 15:45:07 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
ELLIOTJS via RT wrote: Show quoted text
> Michael G Schwern via RT wrote:
>> I think this can boil down to one simple question: What *exactly* is >> wrong with using octal in bitwise ops to the point that you'd >> actively prohibit it? >> >> Reading the original PBP on this, the point was to avoid people who >> mistake 0123 for 123 and think it's just padding. There's nothing >> actually wrong with octal numbers.
> > To quote: "To avoid this covert transmutation of the numbers, never start a > literal integer with zero. Even if you do intend to specify octal numbers,
don't use a Show quoted text
> leading zero, as that may still mislead inattentive future readers of your
code." Show quoted text
> > What part of "never" do you not understand?
That's just the rule, not the reasoning. I dislike blindly following rules, it's better to examine the argument leading up to the rule. Rules are often situational. Once you know the reasoning behind the rule you can know when and where to apply it. The argument against octal comes from the idea that the user has mistakenly used 0123 to mean 123. That they don't realize they can't pad numbers with zeros. I've never actually seen that mistake, nor heard that argument, but I'll accept that Damian has encountered the problem when teaching beginners. But as I laid out, this is unlikely to apply to someone using bitwise ops. In that case it's A) getting in the way and B) missing the real mistake which is using a decimal or string. Would you argue that they probably DID make a mistake? I was thinking about this some while riding around. It's very easy to dismiss this all as "exceptional" and stick to the simple rule "don't use literal octals". But if I wanted simple rules that don't actually apply to the messy reality I'd program Java. DWIM is simple for the user, but not necessary for the poor schmuck implementing it. Still, we value it here in Perl enough to go the extra step. Like tests, every false reading degrades my confidence in a tool's utility. That's why I'm continuing to push for a fix in Perl::Critic itself rather than hacking my own .perlcriticrc or spreading "## no critic" around. Besides, it's not like PBP hasn't been wrong before. It's not some set of stone tablets from God to Damian to Perl::Critic. I see perlcritic doesn't ding me for my use of floating point $VERSION despite 17.3 clearly stating "Don't use floating-point version numbers." -- Ahh email, my old friend. Do you know that revenge is a dish that is best served cold? And it is very cold on the Internet!
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 18:23:38 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Michael G Schwern via RT wrote: Show quoted text
> That's just the rule, not the reasoning. I dislike blindly following > rules, it's better to examine the argument leading up to the rule. > Rules are often situational. Once you know the reasoning behind the > rule you can know when and where to apply it.
Then turn the rule off. If you don't agree with the policy, don't use it. Show quoted text
> The argument against octal comes from the idea that the user has > mistakenly used 0123 to mean 123. That they don't realize they can't > pad numbers with zeros. I've never actually seen that mistake, nor > heard that argument, but I'll accept that Damian has encountered the > problem when teaching beginners.
You are not an average programmer. You'd be surprised by some stuff I've seen. Your separate complaint about "no strict" is in this vein as well. Most programmers shouldn't be doing /anything/ that requires no strict. I'm very glad to be working with a language that supports things like no strict. That doesn't mean you should be using it all over the place in average code. The code that you personally write is exceptional, in more than one way. You shouldn't expect things designed for the common programmer to cover the things that you write. Show quoted text
> But as I laid out, this is unlikely to apply to someone using bitwise > ops. In that case it's A) getting in the way and B) missing the real > mistake which is using a decimal or string. Would you argue that > they probably DID make a mistake?
The whole reason for the entry in PBP is to make your intent blindingly obvious. If, say, octal numbers were written using 0o777, things might be different. Show quoted text
> I was thinking about this some while riding around. It's very easy > to dismiss this all as "exceptional" and stick to the simple rule > "don't use literal octals". But if I wanted simple rules that don't > actually apply to the messy reality I'd program Java. DWIM is simple > for the user, but not necessary for the poor schmuck implementing it. > Still, we value it here in Perl enough to go the extra step.
Yup. Show quoted text
> Like tests, every false reading degrades my confidence in a tool's > utility. That's why I'm continuing to push for a fix in Perl::Critic > itself rather than hacking my own .perlcriticrc or spreading "## no > critic" around.
Have you looked at the P::C source? :] Show quoted text
> Besides, it's not like PBP hasn't been wrong before. It's not some > set of stone tablets from God to Damian to Perl::Critic.
As he says in the introduction in the book. P::C's role is to enable you to enforce the set of rules that you agree with. Show quoted text
> I see perlcritic doesn't ding me for my use of floating point > $VERSION despite 17.3 clearly stating "Don't use floating-point > version numbers."
No, it doesn't. Yet. Care to contribute one that does? (Actually, there's two policies in the TODO related to requiring the version pragma and three part version numbers.) ... Let's turn this question around. Are there any places where you personally would like this policy to complain?
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 18:40:19 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Elliot Shank via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=31977 > > > Michael G Schwern via RT wrote:
>> That's just the rule, not the reasoning. I dislike blindly following >> rules, it's better to examine the argument leading up to the rule. >> Rules are often situational. Once you know the reasoning behind the >> rule you can know when and where to apply it.
> > Then turn the rule off. If you don't agree with the policy, don't use it.
Somebody has to decide on the defaults. Show quoted text
>> The argument against octal comes from the idea that the user has >> mistakenly used 0123 to mean 123. That they don't realize they can't >> pad numbers with zeros. I've never actually seen that mistake, nor >> heard that argument, but I'll accept that Damian has encountered the >> problem when teaching beginners.
> > You are not an average programmer. You'd be surprised by some stuff I've seen.
Not applicable, I'm not doing anything particularly bizarre here. I disagree with the implied notion that perlcritic isn't useful across all spectrums of abilities. To back away from the goal is to give "expert" programmers (whether they actually are or just think they are) carte blanche. As I pointed out earlier, it even did a good job on the hairball of MakeMaker. There is value even to experts. Anyhow, I agree with the general idea that 0xxx might be confusing. I disagree that there aren't sensible exceptions. Show quoted text
> Your separate complaint about "no strict" is in this vein as well. > Most programmers shouldn't be doing /anything/ that requires no strict. > I'm very glad to be working with a language that supports things like no
strict. Show quoted text
> That doesn't mean you should be using it all over the place in average code.
Many programmers wouldn't even bother to turn it on in the first place. At some point it's ok for perlcritic to read some of the more obviously implicit "I know what I'm doing" rather than having to state it explicitly. "Code before strictures are enabled" is a pretty well accepted bad practice. Selectively turning off individual strictures in limited scopes is speculation. If nothing else speculative critics should not be of highest severity. You can narrow the critique against turning off strict even more. There are valid reasons to turn off strict references, even for mere mortal programmers. Method generation isn't that hard and I'd rather teach that than see people use AUTOLOAD which is what they usually reach for first. (Hey, does PC complain about AUTOLOAD?... nope) But there's no good reason to turn off strict vars or subs. "no strict 'refs'" in a limited scope, ok. Any other use of "no strict", bad. Show quoted text
>> But as I laid out, this is unlikely to apply to someone using bitwise >> ops. In that case it's A) getting in the way and B) missing the real >> mistake which is using a decimal or string. Would you argue that >> they probably DID make a mistake?
> > The whole reason for the entry in PBP is to make your intent blindingly obvious. > If, say, octal numbers were written using 0o777, things might be different.
There's obvious and then there's silly. Sometimes eschewing certain language idioms in favor of "obvious" code can actually have the opposite effect. So far everyone I've put the recommend code in front of: $mask &= oct 755; has scratched their head as to why someone would do that instead of 0755. I would argue it has made it less obvious. If there's a non-obvious part there it's all about using bitwise ops, not the octal number. It's like someone writing: my $count = scalar @array; You could argue that "scalar" makes it more obvious and protects you against mistakes like: my($count) = @array; But this reasoning is speculative. The mistake is easily testable. The "improved" idiom is verbose, not idiomatic and implies a fear of Perlish thinking (in this case, embracing contexts). It adds in "scaffolding" code (to use a Damianism) that really doesn't do anything. Finally, it is a documented part of Perl. Another example might be this: if( foo(@args) ) { do_bar(); } One could argue that all the explicit parens make it "obvious" what's going on. That may be so, but they also clutter up the space with lots of parens and braces doing different things. Compare... if( foo @args ) { do_bar; } Or even: do_bar if foo @args; Then it's ok to have your parens back. do_bar() if foo(@args); Show quoted text
>> Like tests, every false reading degrades my confidence in a tool's >> utility. That's why I'm continuing to push for a fix in Perl::Critic >> itself rather than hacking my own .perlcriticrc or spreading "## no >> critic" around.
> > Have you looked at the P::C source? :]
No, but I know where I put my own and why. Having to put "no critic" on something genuinely weird is fine. These are the valid critics in MakeMaker that I individually hushed with specific reasons. ./lib/ExtUtils/MakeMaker.pm:sub prompt ($;$) { ## no critic ./lib/ExtUtils/MM.pm:eval "require $class" unless $INC{"ExtUtils/MM_$OS.pm"}; ## no critic ./lib/ExtUtils/MM_Unix.pm: if( open(STDERR_COPY, '>&STDERR') ) { ## no critic ./lib/ExtUtils/MM_Unix.pm: open STDERR, ">&STDERR_COPY" ## no critic ./lib/ExtUtils/MM_Unix.pm: $result = eval($eval); ## no critic ./lib/ExtUtils/MM_VMS.pm: %xs = map { s/.xs$//; ($_,1) } glob('*.xs'); ## no critic I agree with perlcritic, I am breaking good programming practice, and I'm fine with having to think about and note the exceptions. perlcritic found a bunch more weird things that I instead altered to conform with perlcritic's recommendations. They were good recommendations. This is why I'm so adamant that perlcritic not consider expert programmers exceptional. Show quoted text
>> Besides, it's not like PBP hasn't been wrong before. It's not some >> set of stone tablets from God to Damian to Perl::Critic.
> > As he says in the introduction in the book. P::C's role is to enable you to enforce the > set of rules that you agree with.
Ahh, but somebody has to choose the defaults and the rules. And presumably they put some thought into that. The better it works out of the box the better chance someone will use it. When you're already skeptical about the value of a tool, being told you have to spend a bunch of time tweaking tends to just fuel that skepticism. Show quoted text
>> I see perlcritic doesn't ding me for my use of floating point >> $VERSION despite 17.3 clearly stating "Don't use floating-point >> version numbers."
> > No, it doesn't. Yet. Care to contribute one that does?
Even Damian doesn't think that's a good idea anymore. I'm more than a little horrified because it implies that Perl::Critic *is* blindly following PBP! The solution is worse than the problem. version.pm introduces all sorts of fascinating complications, much worse than the odd floating point error. This is a spot where I can say I probably know more about it than Damian, although perhaps not after he published PBP and got all the fun feedback about that particular recommendation. I have just two requirements for a version number: 1) It compares as a number and without warnings. 2) It only goes up over time. These days I'm recommending integer version numbers, but X.YYY is still fine. http://use.perl.org/~schwern/journal/35127 There is one part of the PBP version discussion that I would enforce: Don't use vstrings. I'd add in another, that $VERSION should not be /^\d\.\d$/; That is, just one decimal point. This strongly implies that the user expects 1.2 < 1.11. A final critic is if $VERSION is a number (not a string) and /0$/ as in 1.10. The trailing zero will be lost. It's possible it might be handy to recommend all simple decimal versions be strings. Show quoted text
> Let's turn this question around. Are there any places where you personally > would like this policy to complain?
Not personally, no, I haven't run into this yet in my own code and never run into anyone who got confused. Like I said I can accept the idea that in the general case bare octal numbers may be used incorrectly by a beginner. I've never run into it myself, but I'm willing to defer to Damian's wider newbie teaching experience. As the policy is more than a bit speculative, and the mistake quickly revealed, I wouldn't put it at the highest severity. Compare with, say, the policy against 2 arg open. That's a clear security hole and thus perlcritic can say, with good certainty, that 2 arg open is a bad idea. It's also the sort of thing that, if it's never explained to you, you probably never would have known it's a problem. I didn't know until yesterday. As opposed to the notion that 0123 == 123. A notion that won't last very long if you actually try to apply it. -- THIS I COMMAND!
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sat, 29 Dec 2007 21:35:03 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <elliotjs [...] cpan.org>
Michael G Schwern via RT wrote: Show quoted text
>> Michael G Schwern via RT wrote:
>>> That's just the rule, not the reasoning. I dislike blindly following >>> rules, it's better to examine the argument leading up to the rule. >>> Rules are often situational. Once you know the reasoning behind the >>> rule you can know when and where to apply it.
>> Then turn the rule off. If you don't agree with the policy, don't use it.
> > Somebody has to decide on the defaults.
Yup. All policies are turned on by default. Even policies from add-on distributions. Show quoted text
> Anyhow, I agree with the general idea that 0xxx might be confusing. I > disagree that there aren't sensible exceptions.
You can get agreement from me on that in the obvious permissions situations, but not otherwise. Show quoted text
> At some point it's ok for perlcritic to read some of the more obviously > implicit "I know what I'm doing" rather than having to state it explicitly.
Define obvious. For a computer and for an arbitrary programmer. Show quoted text
> There's obvious and then there's silly.
For whom? Show quoted text
> So far everyone I've put the recommend code in front of: > > $mask &= oct 755; > > has scratched their head as to why someone would do that instead of 0755. I > would argue it has made it less obvious.
Yes, for something dealing with file permissions, I accept octal. However, how is P::C supposed to know this? Show quoted text
> Ahh, but somebody has to choose the defaults and the rules. And presumably > they put some thought into that.
Don't blame me. I didn't write this policy. :] Show quoted text
> There is one part of the PBP version discussion that I would enforce: Don't > use vstrings.
Already covered: ValuesAndExpressions::ProhibitVersionStrings Show quoted text
>> Let's turn this question around. Are there any places where you personally >> would like this policy to complain?
> > Not personally, no, I haven't run into this yet in my own code and never run > into anyone who got confused.
Then why are we having this discussion? :] (I know, I know. It's just a rhetorical question.) Show quoted text
> As opposed to the notion that 0123 == 123. A notion that won't last very long > if you actually try to apply it.
The problem is 0123 == $x. Conclusion: I am willing, when I have enough tuits, to make exceptions for the obvious file permissions cases. I am not willing to make others. But that's just me. I'm not the only one on the project and anyone else is free to do as you suggest.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sun, 30 Dec 2007 14:43:17 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
ELLIOTJS via RT wrote: Show quoted text
> Conclusion: I am willing, when I have enough tuits, to make exceptions for the obvious > file permissions cases. I am not willing to make others. > > But that's just me. I'm not the only one on the project and anyone else is free to do > as you suggest.
I was thinking something similar, especially after I saw your Twitter message. Why don't I report the bitwise/octal thing as a separate bug to move it out of the way and then we can fix the obvious [1] Unix mode issues? [1] Oh no, I can't define obvious!!!!!1!1one ;P -- But there's no sense crying over every mistake. You just keep on trying till you run out of cake. -- Jonathan Coulton, "Still Alive"
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sun, 30 Dec 2007 17:32:15 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <elliotjs [...] cpan.org>
Michael G Schwern via RT wrote: Show quoted text
> ELLIOTJS via RT wrote:
>> Conclusion: I am willing, when I have enough tuits, to make exceptions for the obvious >> file permissions cases. I am not willing to make others. >> >> But that's just me. I'm not the only one on the project and anyone else is free to do >> as you suggest.
> > I was thinking something similar, especially after I saw your Twitter message.
Basically, my reason for this is that I hate octal (with the exception of the natural match with permissions) due to its mismatch with bytes and want to discourage its use. So, if there's something that makes using it annoying, I'm for it. :]
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sun, 30 Dec 2007 19:45:08 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On Dec 30, 2007, at 5:33 PM, ELLIOTJS via RT wrote: Show quoted text
> Basically, my reason for this is that I hate octal (with the > exception of the natural match with permissions) due to its > mismatch with bytes and want to discourage its use. So, if there's > something that makes using it annoying, I'm for it. :]
:-) I love this quote! Chris
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Sun, 22 Jun 2008 16:44:26 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Michael G Schwern via RT wrote: Show quoted text
> Queue: Perl-Critic > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=31977 > > > Similar issues with dbmopen, mkdir and umask.
Just checked in changes for the permissions arguments to chmod, dbmopen, mkdir, sysopen, and umask.
Subject: Re: [rt.cpan.org #31977] "Integer with leading zeros" exceptions for chmod()?
Date: Fri, 04 Jul 2008 13:00:51 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
Elliot Shank via RT wrote: Show quoted text
> Michael G Schwern via RT wrote:
>> Similar issues with dbmopen, mkdir and umask.
> > Just checked in changes for the permissions arguments to chmod, > dbmopen, mkdir, sysopen, and umask.
Just released in 1.088.