Subject: | octals and bitwise ops |
This is split off of bug 31977 so we can deal with it later as it has
proven contentious.
perlcritic complains about octal numbers in bitwise ops.
$ echo 'use strict; $mode &= 0755' | perlcritic
Integer with leading zeros at line 1, column 23. See page 58 of PBP.
(Severity: 5)
This is part of the general prohibition against octals on the theory
that a newbie will be surprised because in the real world 0123 means 123.
I'd argue that an exception should be made for bitwise ops on the
grounds that...
A) if you're using bitwise ops you probably know what you're doing, so
the critic is just getting in the way of the writer.
B) bitwise ops on Unix permissions are fairly common (for bitwise ops),
or at least not considered poor practice, and octal numbers are a good
way to express them.
C) that the "good practice" of $mode &= oct 755 is actually going to be
more confusing to an experienced reader. I'd certainly wonder. It's
like seeing my $num = scalar @array; "Oh, the author doesn't actually
grok Perl".
D) if you're a newbie reading code which uses bitwise ops the most
confusing thing on the page isn't going to be 0755 it's going to be &=,
so I don't think the prohibition is going to result in easier to read code.
Going further, perlcritic misses the real bad practices which are...
$mode &= 755;
$mode &= "0755";
The proper critics should be "decimal number used with bitwise op" and
"string used with bitwise op".
To sum up, wrt bitwise ops, perlcritic A) prohibits the good and B) does
not prohibit the bad.