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.1 by root, Thu Jul 9 16:14:16 2009 UTC vs.
Revision 1.13 by root, Tue Sep 1 13:42:29 2009 UTC

18two typical (or not so typical - use your common sense) specimens of 18two typical (or not so typical - use your common sense) specimens of
19Perl coders. 19Perl coders.
20 20
21=over 4 21=over 4
22 22
23=item no warnings
24
25Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w>
26switch: 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
28spirit of Perl.
29
30Most prominently, the warnings related to C<undef>. There is nothing wrong
31with C<undef>: it has well-defined semantics, it is useful, and spitting
32out warnings you never asked for is just evil.
33
34So every module needs C<no warnings> to avoid somebody accidentally using
35C<-w> and forcing his bad standards on our code. No will do. Really, the
36C<-w> switch should only enable wanrings for the main program.
37
38Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a
39favourable way), but standard utilities, such as L<prove>, or MakeMaker
40when running C<make test> enable them blindly.
41
23=item use strict qw(subs vars) 42=item use strict qw(subs vars)
24 43
25Using C<use strict> is definitely common sense, but C<use strict 44Using C<use strict> is definitely common sense, but C<use strict
26'refs'> definitely overshoots it's usefulness. After almost two 45'refs'> definitely overshoots its usefulness. After almost two
27decades of Perl hacking, we decided that it does more harm than being 46decades of Perl hacking, we decided that it does more harm than being
28useful. Specifically, constructs like these: 47useful. Specifically, constructs like these:
29 48
30 @{ $var->[0] } 49 @{ $var->[0] }
31 50
32Must be written like this, when C<use strict 'refs'> is in scope, and 51Must be written like this (or similarly), when C<use strict 'refs'> is in
33C<$var> can legally be C<undef>: 52scope, and C<$var> can legally be C<undef>:
34 53
35 @{ $var->[0] || [] } 54 @{ $var->[0] || [] }
36 55
37This is annoying, and doesn't shield against obvious mistakes such as 56This is annoying, and doesn't shield against obvious mistakes such as
38using C<"">, so one would even have to write: 57using C<"">, so one would even have to write (at least for the time
58being):
39 59
40 @{ defined $var->[0] ? $var->[0] : [] } 60 @{ defined $var->[0] ? $var->[0] : [] }
41 61
42... which nobody with a bit of common sense would consider 62... which nobody with a bit of common sense would consider
63writing.
64
43writing. Curiously enough, sometimes, perl is not so strict, as this works 65Curiously enough, sometimes perl is not so strict, as this works even with
44even with C<use strict> in scope: 66C<use strict> in scope:
45 67
46 for (@{ $var->[0] }) { ... 68 for (@{ $var->[0] }) { ...
47 69
48If that isnt hipocrasy! And all that from a mere program! 70If that isn't hipocrasy! And all that from a mere program!
49 71
50=item use feature qw(say state given) 72=item use feature qw(say state given)
51 73
52We found it annoying that we always have to enable extra features. If 74We found it annoying that we always have to enable extra features. If
53something breaks because it didn't anticipate future changes, so be 75something breaks because it didn't anticipate future changes, so be
54it. 5.10 broke almost all our XS modules and nobody cared either - and few 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
55modules that are no longer maintained work with newer versions of Perl, 80Few modules that are not actively maintained work with newer versions of
56regardless of use feature. 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.
57 83
58If your code isn'talive, it's dead, jim. 84If your code isn't alive, it's dead, jim - be an active maintainer.
59 85
60=item no warnings 86=item mucho reduced memory usage
61 87
62The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even 88Just using all those pragmas mentioned in the SYNOPSIS together wastes
63though we don't care if other people use warnings (and certainly there are 89<blink>I<< B<776> kilobytes >></blink> of precious memory in my perl, for
64useful ones), a lot of warnings simply go against the spirit of Perl, most 90I<every single perl process using our code>, which on our machines, is a
65prominently, the warnings related to C<undef>. There is nothing wrong with 91lot. In comparison, this module only uses I<< B<four> >> kilobytes (I even
66C<undef>: it has well-defined semantics, it is useful, and spitting out 92had to write it out so it looks like more) of memory on the same platform.
67warnings you never asked for is just evil.
68
69So every module needs C<no warnings> to avoid somebody accidentally using
70C<-w> and forcing his bad standards on our code. No will do.
71
72(Also, why isn't this a C<use feature> switch? Adding warnings is
73apparently considered O.K., even if it breaks your programs).
74
75=item much less memory
76
77Just using all those pragmas together waste <blink>I<< B<776> kilobytes
78>></blink> of precious memory in my perl, for I<every single perl process
79using our code>, which on our machines, is a lot.
80 93
81The money/time/effort/electricity invested in these gigabytes (probably 94The money/time/effort/electricity invested in these gigabytes (probably
82petabytes globally!) of wasted memory could easily save 42 trees, and a 95petabytes globally!) of wasted memory could easily save 42 trees, and a
83kitten! 96kitten!
84 97
98Unfortunately, until everybods applies more common sense, there will still
99often be modules that pull in the monster pragmas. But one can hope...
100
85=cut 101=cut
86 102
87package Async::Interrupt; 103package common::sense;
88 104
105our $VERSION = '1.0';
106
89no warnings; 107# no warnings;
108# 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
110# utf8 layer reserved parenthesis taint closure);
111# BEGIN { warn join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS} };
90 112
91BEGIN { 113# overload should be included
92 $VERSION = '0.03';
93 114
94 require XSLoader; 115sub import {
95 XSLoader::load Async::Interrupt::, $VERSION; 116 # verified with perl 5.8.0, 5.10.0
117 ${^WARNING_BITS} = "\xfc\xff\xff\x00\xcf\xf3\xcf\xc0\xf3\xcc\x33\x03";
118
119 # use strict vars subs
120 $^H |= 0x00000600;
121
122 # use feature
123 $^H{feature_switch} =
124 $^H{feature_say} =
125 $^H{feature_state} = 1;
96} 126}
97 127
98our $DIED = sub { warn "$@" };
99
100=cut
101
1021; 1281;
103 129
104=back 130=back
105 131
106=head1 EXAMPLE 132=head1 THERE IS NO 'no common::sense'!!!! !!!! !!
107 133
108There really should be a complete C/XS example. Bug me about it. 134This module doesn't offer an unimport. First of all, it wastes even more
135memory, second, and more importantly, who with even a bit of common sense
136would want no common sense?
109 137
110=head1 IMPLEMENTATION DETAILS AND LIMITATIONS 138=head1 STABILITY AND FUTURE VERSIONS
111 139
112This module works by "hijacking" SIGKILL, which is guaranteed to be always 140Future versions might change just about everything in this module. We
113available in perl, but also cannot be caught, so is always available. 141might test our modules and upload new ones working with newer versions of
142this module, and leave you standing in the rain because we didn't tell
143you.
114 144
115Basically, this module fakes the receive of a SIGKILL signal and 145Most likely, we will pick a few useful warnings, instead of just disabling
116then catches it. This makes normal signal handling slower (probably 146all of them. And maybe we will load some nifty modules that try to emulate
117unmeasurably), but has the advantage of not requiring a special runops nor 147C<say> or so with perls older than 5.10 (this module, of course, should
118slowing down normal perl execution a bit. 148work with older perl versions - supporting 5.8 for example is just common
149sense at this time. Maybe not in the future, but of course you can trust
150our common sense to be consistent with, uhm, our opinion).
119 151
120It assumes that C<sig_atomic_t> and C<int> are both exception-safe to 152=head1 WHAT OTHER PEOPLE HAD TO SAY ABOUT THIS MODULE
121modify (C<sig_atomic_> is used by this module, and perl itself uses 153
122C<int>, so we can assume that this is quite portable, at least w.r.t. 154apeiron
123signals). 155
156 "... wow"
157 "I hope common::sense is a joke."
158
159crab
160
161 "i wonder how it would be if joerg schilling wrote perl modules."
162
163H.Merijn Brand
164
165 "Just one more reason to drop JSON::XS from my distribution list"
166
167Pista Palo
168
169 "Something in short supply these days..."
170
171Steffen Schwigon
172
173 "This module is quite for sure *not* just a repetition of all the other
174 'use strict, use warnings'-approaches, and it's also not the opposite.
175 [...] And for its chosen middle-way it's also not the worst name ever.
176 And everything is documented."
177
178BKB
179
180 "[Deleted - thanks to Steffen Schwigon for pointing out this review was
181 in error.]"
182
183Somni
184
185 "the arrogance of the guy"
186 "I swear he tacked somenoe else's name onto the module
187 just so he could use the royal 'we' in the documentation"
188
189dngor
190
191 "Heh. '"<elmex at ta-sa.org>"' The quotes are semantic
192 distancing from that e-mail address."
193
194Jerad Pierce
195
196 "Awful name (not a proper pragma), and the SYNOPSIS doesn't tell you
197 anything either. Nor is it clear what features have to do with "common
198 sense" or discipline."
199
200acme
201
202 "THERE IS NO 'no common::sense'!!!! !!!! !!"
203
204apeiron (meta-comment)
205
206 How about quoting this: get a clue, you fucktarded amoeba.
124 207
125=head1 AUTHOR 208=head1 AUTHOR
126 209
127 Marc Lehmann <schmorp@schmorp.de> 210 Marc Lehmann <schmorp@schmorp.de>
128 http://home.schmorp.de/ 211 http://home.schmorp.de/
129 212
213 Robin Redeker, "<elmex at ta-sa.org>".
214
130=cut 215=cut
131 216

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines