ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/common-sense/sense.pm
(Generate patch)

Comparing common-sense/sense.pm (file contents):
Revision 1.14 by root, Tue Sep 1 13:54:56 2009 UTC vs.
Revision 1.15 by root, Tue Sep 1 14:28:20 2009 UTC

9 # roughly the same as, with much lower memory usage: 9 # roughly the same as, with much lower memory usage:
10 # 10 #
11 # use strict qw(vars subs); 11 # use strict qw(vars subs);
12 # use feature qw(say state switch); 12 # use feature qw(say state switch);
13 # no warnings; 13 # no warnings;
14 # use warnings qw(FATAL closed threads internal debugging pack substr malloc
15 # unopened portable prototype inplace io pipe unpack regexp
16 # deprecated exiting redefine glob digit printf utf8 layer
17 # reserved parenthesis taint closure semicolon);
18 # no warnings qw(exec newline);
14 19
15=head1 DESCRIPTION 20=head1 DESCRIPTION
16 21
17This module implements some sane defaults for Perl programs, as defined by 22This module implements some sane defaults for Perl programs, as defined by
18two typical (or not so typical - use your common sense) specimens of 23two typical (or not so typical - use your common sense) specimens of
19Perl coders. 24Perl coders.
20 25
21=over 4 26=over 4
22 27
23=item no warnings 28=item use strict qw(subs vars)
29
30Using C<use strict> is definitely common sense, but C<use strict
31'refs'> definitely overshoots its usefulness. After almost two
32decades of Perl hacking, we decided that it does more harm than being
33useful. Specifically, constructs like these:
34
35 @{ $var->[0] }
36
37Must be written like this (or similarly), when C<use strict 'refs'> is in
38scope, and C<$var> can legally be C<undef>:
39
40 @{ $var->[0] || [] }
41
42This is annoying, and doesn't shield against obvious mistakes such as
43using C<"">, so one would even have to write (at least for the time
44being):
45
46 @{ defined $var->[0] ? $var->[0] : [] }
47
48... which nobody with a bit of common sense would consider
49writing.
50
51Curiously enough, sometimes perl is not so strict, as this works even with
52C<use strict> in scope:
53
54 for (@{ $var->[0] }) { ...
55
56If that isn't hypocrisy! And all that from a mere program!
57
58
59=item use feature qw(say state given)
60
61We found it annoying that we always have to enable extra features. If
62something breaks because it didn't anticipate future changes, so be
63it. 5.10 broke almost all our XS modules and nobody cared either (or at
64least I know of nobody who really complained about gratuitous changes -
65as opposed to bugs).
66
67Few modules that are not actively maintained work with newer versions of
68Perl, regardless of use feature or not, so a new major perl release means
69changes to many modules - new keywords are just the tip of the iceberg.
70
71If your code isn't alive, it's dead, Jim - be an active maintainer.
72
73
74=item no warnings, but a lot of new lexical errors
24 75
25Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w> 76Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w>
26switch: Even though we don't care if other people use warnings (and 77switch: Even though we don't care if other people use warnings (and
27certainly there are useful ones), a lot of warnings simply go against the 78certainly there are useful ones), a lot of warnings simply go against the
28spirit of Perl. 79spirit of Perl.
29 80
30Most prominently, the warnings related to C<undef>. There is nothing wrong 81Most prominently, the warnings related to C<undef>. There is nothing wrong
31with C<undef>: it has well-defined semantics, it is useful, and spitting 82with C<undef>: it has well-defined semantics, it is useful, and spitting
32out warnings you never asked for is just evil. 83out warnings you never asked for is just evil.
33 84
34So every module needs C<no warnings> to avoid somebody accidentally using 85So every one of our modules did C<no warnings> in the past, to avoid
35C<-w> and forcing his bad standards on our code. No will do. Really, the 86somebody accidentally using and forcing his bad standards on our code. No
36C<-w> switch should only enable wanrings for the main program. 87will do. Really, the C<-w> switch should only enable wanrings for the main
88program only.
37 89
38Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a 90Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a
39favourable way), but standard utilities, such as L<prove>, or MakeMaker 91favourable way, calling it outright "wrong"), but standard utilities, such
40when running C<make test> enable them blindly. 92as L<prove>, or MakeMaker when running C<make test>, still enable them
93blindly.
41 94
42=item use strict qw(subs vars) 95Anyways, since C<use warnings> is inacceptable, many people (including us
96before we created common::sense) just flat out disabled all warnings. For
97this module, we actually sat down a few hours and went through all the
98warnings, and identified all the useful (accordign to common sense)
99warnings.
43 100
44Using C<use strict> is definitely common sense, but C<use strict 101This resulted in the rather impressive list in the SYNOPSIS. When we
45'refs'> definitely overshoots its usefulness. After almost two 102weren't sure, we didn't include the warning, so the list might grow in
46decades of Perl hacking, we decided that it does more harm than being 103the future (we might have made a mistake, too, so the list might shrink
47useful. Specifically, constructs like these: 104again).
48 105
49 @{ $var->[0] } 106Note the presence of C<FATAL> in the list: we do not think that the
107conditions caught by these warnings are worthy of a warning, we I<insist>
108that they are worthy of stopping your program, instantly. They are bugs!
50 109
51Must be written like this (or similarly), when C<use strict 'refs'> is in 110Therefore we consider C<common::sense> to be much stricter than C<use
52scope, and C<$var> can legally be C<undef>: 111warnings>, which is good if you are into strict things (we are not,
112actually, but these things tend to be subjective).
53 113
54 @{ $var->[0] || [] } 114After deciding on the list, we ran the module against all of our code that
115uses C<common::sense> (that is almost all of our code), and found only one
116occurence where one of them caused a problem: one of elmex's (unreleased)
117modules contained:
55 118
56This is annoying, and doesn't shield against obvious mistakes such as 119 $fmt =~ s/([^\s\[]*)\[( [^\]]* )\]/\x0$1\x1$2\x0/xgo;
57using C<"">, so one would even have to write (at least for the time
58being):
59 120
60 @{ defined $var->[0] ? $var->[0] : [] } 121We quickly agreed that indeed the code should be changed, even though it
122happened to do the right thing when the warning was switched off.
61 123
62... which nobody with a bit of common sense would consider
63writing.
64
65Curiously enough, sometimes perl is not so strict, as this works even with
66C<use strict> in scope:
67
68 for (@{ $var->[0] }) { ...
69
70If that isn't hipocrasy! And all that from a mere program!
71
72=item use feature qw(say state given)
73
74We found it annoying that we always have to enable extra features. If
75something breaks because it didn't anticipate future changes, so be
76it. 5.10 broke almost all our XS modules and nobody cared either (or at
77leats I know of nobody who really complained about gratitious changes - as
78opposed to bugs).
79
80Few modules that are not actively maintained work with newer versions of
81Perl, regardless of use feature or not, so a new major perl release means
82changes to many modules - new keywords are just the tip of the iceberg.
83
84If your code isn't alive, it's dead, jim - be an active maintainer.
85 124
86=item mucho reduced memory usage 125=item mucho reduced memory usage
87 126
88Just using all those pragmas mentioned in the SYNOPSIS together wastes 127Just using all those pragmas mentioned in the SYNOPSIS together wastes
89<blink>I<< B<776> kilobytes >></blink> of precious memory in my perl, for 128<blink>I<< B<776> kilobytes >></blink> of precious memory in my perl, for
100 139
101=cut 140=cut
102 141
103package common::sense; 142package common::sense;
104 143
105our $VERSION = '1.0'; 144our $VERSION = '2.0';
145
146# paste this into pelr to find bitmask
106 147
107# no warnings; 148# no warnings;
108# use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype 149# use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype
109# inplace io pipe unpack regexp deprecated exiting redefine glob digit printf 150# inplace io pipe unpack regexp deprecated exiting redefine glob digit printf
110# utf8 layer reserved parenthesis taint closure semicolon); 151# utf8 layer reserved parenthesis taint closure semicolon);
139=head1 STABILITY AND FUTURE VERSIONS 180=head1 STABILITY AND FUTURE VERSIONS
140 181
141Future versions might change just about everything in this module. We 182Future versions might change just about everything in this module. We
142might test our modules and upload new ones working with newer versions of 183might test our modules and upload new ones working with newer versions of
143this module, and leave you standing in the rain because we didn't tell 184this module, and leave you standing in the rain because we didn't tell
144you. 185you. In fact, we did so when switching from 1.0 to 2.0, which enabled gobs
186of warnings, and made them FATAL on top.
145 187
146Most likely, we will pick a few useful warnings, instead of just disabling
147all of them. And maybe we will load some nifty modules that try to emulate 188Maybe we will load some nifty modules that try to emulate C<say> or so
148C<say> or so with perls older than 5.10 (this module, of course, should 189with perls older than 5.10 (this module, of course, should work with older
149work with older perl versions - supporting 5.8 for example is just common 190perl versions - supporting 5.8 for example is just common sense at this
150sense at this time. Maybe not in the future, but of course you can trust 191time. Maybe not in the future, but of course you can trust our common
151our common sense to be consistent with, uhm, our opinion). 192sense to be consistent with, uhm, our opinion).
152 193
153=head1 WHAT OTHER PEOPLE HAD TO SAY ABOUT THIS MODULE 194=head1 WHAT OTHER PEOPLE HAD TO SAY ABOUT THIS MODULE
154 195
155apeiron 196apeiron
156 197
200 241
201acme 242acme
202 243
203 "THERE IS NO 'no common::sense'!!!! !!!! !!" 244 "THERE IS NO 'no common::sense'!!!! !!!! !!"
204 245
205apeiron (meta-comment) 246apeiron (meta-comment about us commenting^Wquoting his comment)
206 247
207 How about quoting this: get a clue, you fucktarded amoeba. 248 How about quoting this: get a clue, you fucktarded amoeba.
208 249
209=head1 AUTHOR 250=head1 AUTHOR
210 251

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines