ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/common-sense/sense.pm
Revision: 1.14
Committed: Tue Sep 1 13:54:56 2009 UTC (14 years, 10 months ago) by root
Branch: MAIN
Changes since 1.13: +4 -3 lines
Log Message:
*** empty log message ***

File Contents

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