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.17 by root, Tue Sep 8 16:04:52 2009 UTC vs.
Revision 1.21 by root, Fri Oct 30 02:58:05 2009 UTC

4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use common::sense; 7 use common::sense;
8 8
9 # roughly the same as, with much lower memory usage: 9 # supposed to be the same, with much lower memory usage, as:
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 14 # use warnings qw(FATAL closed threads internal debugging pack substr malloc
19 19
20=head1 DESCRIPTION 20=head1 DESCRIPTION
21 21
22This module implements some sane defaults for Perl programs, as defined by 22This module implements some sane defaults for Perl programs, as defined by
23two typical (or not so typical - use your common sense) specimens of Perl 23two typical (or not so typical - use your common sense) specimens of Perl
24coders. 24coders. In fact, after working out details on which warnings and strict
25modes to enable and make fatal, we found that we (and our code written so
26far, and others) fully agree on every option, even though we never used
27warnings before, so it seems this module indeed reflects a "common" sense
28among some long-time Perl coders.
25 29
26=over 4 30=over 4
27 31
28=item use strict qw(subs vars) 32=item use strict qw(subs vars)
29 33
41 45
42This is annoying, and doesn't shield against obvious mistakes such as 46This 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 47using C<"">, so one would even have to write (at least for the time
44being): 48being):
45 49
46 @{ defined $var->[0] ? $var->[0] : [] } 50 @{ defined $var->[0] ? $var->[0] : [] }
47 51
48... which nobody with a bit of common sense would consider 52... which nobody with a bit of common sense would consider
49writing. 53writing: clear code is clearly something else.
50 54
51Curiously enough, sometimes perl is not so strict, as this works even with 55Curiously enough, sometimes perl is not so strict, as this works even with
52C<use strict> in scope: 56C<use strict> in scope:
53 57
54 for (@{ $var->[0] }) { ... 58 for (@{ $var->[0] }) { ...
139 143
140=cut 144=cut
141 145
142package common::sense; 146package common::sense;
143 147
144our $VERSION = '2.0'; 148our $VERSION = '2.01';
145 149
146# paste this into pelr to find bitmask 150# paste this into perl to find bitmask
147 151
148# no warnings; 152# no warnings;
149# use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype 153# use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype
150# inplace io pipe unpack regexp deprecated exiting glob digit printf 154# inplace io pipe unpack regexp deprecated exiting glob digit printf
151# utf8 layer reserved parenthesis taint closure semicolon); 155# utf8 layer reserved parenthesis taint closure semicolon);
154 158
155# overload should be included 159# overload should be included
156 160
157sub import { 161sub import {
158 # verified with perl 5.8.0, 5.10.0 162 # verified with perl 5.8.0, 5.10.0
159 ${^WARNING_BITS} = "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03"; 163 ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";
160 164
161 # use strict vars subs 165 # use strict vars subs
162 $^H |= 0x00000600; 166 $^H |= 0x00000600;
163 167
164 # use feature 168 # use feature
251 255
252apeiron (meta-comment about us commenting^Wquoting his comment) 256apeiron (meta-comment about us commenting^Wquoting his comment)
253 257
254 How about quoting this: get a clue, you fucktarded amoeba. 258 How about quoting this: get a clue, you fucktarded amoeba.
255 259
260quanth
261
262 common sense is beautiful, json::xs is fast, Anyevent, EV are fast and
263 furious. I love mlehmannware ;)
264
265=head1 FREQUQNTLY ASKED QUESTIONS
266
267Or frequently-come-up confusions.
268
269=over 4
270
271=item Is this module meant to be serious?
272
273Yes, we would have put it under the C<Acme::> namespace otherwise.
274
275=item But the manpage is written in a funny/stupid/... way?
276
277This was meant to make it clear that our common sense is a subjective
278thing and other people can use their own notions, taking the steam out
279of anybody who might be offended (as some people are always offended no
280matter what you do).
281
282This was a failure.
283
284But we hope the manpage still is somewhat entertaining even though it
285explains boring rationale.
286
287=item Why do you impose your conventions on my code?
288
289For some reason people keep thinking that C<common::sense> imposes
290process-wide limits, even though the SYNOPSIS makes it clear that it works
291like other similar modules - only on the scope that uses them.
292
293So, no, we don't - nobody is forced to use this module, and using a module
294that relies on common::sense does not impose anything on you.
295
296=item Why do you think only your notion of common::sense is valid?
297
298Well, we don't, and have clearly written this in the documentation to
299every single release. We were just faster than anybody else w.r.t. to
300grabbing the namespace.
301
302=item But everybody knows that you have to use strict and use warnings,
303why do you disable them?
304
305Well, we don't do this either - we selectively disagree with the
306usefulness of some warnings over others. This module is aimed at
307experienced Perl programmers, not people migrating from other languages
308who might be surprised about stuff such as C<undef>.
309
310In fact, this module is considerably I<more> strict than the canonical
311C<use strict; use warnings>, as it makes all warnings fatal in nature, so
312you can get away with as many things as with the canonical approach.
313
314This was not implemented in version 1.0 because of the daunting number
315of warning categories and the difficulty in getting exactly the set of
316warnings you wish (i.e. look at the SYNOPSIS in how complicated it is to
317get a specific set of warnings - it is not reasonable to put this into
318every module, the maintainance effort would be enourmous).
319
320=item But many modules C<use strict> or C<use warnings>, so the memory
321savings do not apply?
322
323I am suddenly so sad.
324
325But yes, that's true. Fortunately C<common::sense> still uses only a
326miniscule amount of RAM.
327
328=item But it adds another dependency to your modules!
329
330It's a fact, yeah. But it's trivial to install, most popular modules have
331many more dependencies and we consider dependencies a good thing - it
332leads to better APIs, more thought about interworking of modules and so
333on.
334
335=item But! But!
336
337Yeah, we know.
338
339=back
340
256=head1 AUTHOR 341=head1 AUTHOR
257 342
258 Marc Lehmann <schmorp@schmorp.de> 343 Marc Lehmann <schmorp@schmorp.de>
259 http://home.schmorp.de/ 344 http://home.schmorp.de/
260 345

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines