ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/common-sense/sense.pm
Revision: 1.12
Committed: Sat Aug 29 08:10:32 2009 UTC (14 years, 8 months ago) by root
Branch: MAIN
Changes since 1.11: +4 -0 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.2 sub import {
108 root 1.3 # no warnings
109 root 1.2 ${^WARNING_BITS} ^= ${^WARNING_BITS};
110 root 1.3
111     # use strict vars subs
112     $^H |= 0x00000600;
113    
114     # use feature
115     $^H{feature_switch} =
116     $^H{feature_say} =
117     $^H{feature_state} = 1;
118 root 1.1 }
119    
120     1;
121    
122     =back
123    
124 root 1.5 =head1 THERE IS NO 'no common::sense'!!!! !!!! !!
125 root 1.4
126     This module doesn't offer an unimport. First of all, it wastes even more
127     memory, second, and more importantly, who with even a bit of common sense
128     would want no common sense?
129    
130 root 1.5 =head1 STABILITY AND FUTURE VERSIONS
131    
132     Future versions might change just about everything in this module. We
133     might test our modules and upload new ones working with newer versions of
134     this module, and leave you standing in the rain because we didn't tell
135     you.
136    
137     Most likely, we will pick a few useful warnings, instead of just disabling
138     all of them. And maybe we will load some nifty modules that try to emulate
139     C<say> or so with perls older than 5.10 (this module, of course, should
140     work with older perl versions - supporting 5.8 for example is just common
141 root 1.6 sense at this time. Maybe not in the future, but of course you can trust
142 root 1.11 our common sense to be consistent with, uhm, our opinion).
143    
144     =head1 WHAT OTHER PEOPLE HAD TO SAY ABOUT THIS MODULE
145    
146     apeiron
147    
148     "... wow"
149     "I hope common::sense is a joke."
150    
151     crab
152 root 1.5
153 root 1.11 "i wonder how it would be if joerg schilling wrote perl modules."
154 root 1.7
155 root 1.11 H.Merijn Brand
156    
157     "Just one more reason to drop JSON::XS from my distribution list"
158 root 1.7
159     Pista Palo
160    
161     "Something in short supply these days..."
162    
163     Steffen Schwigon
164    
165     "This module is quite for sure *not* just a repetition of all the other
166     'use strict, use warnings'-approaches, and it's also not the opposite.
167     [...] And for its chosen middle-way it's also not the worst name ever.
168     And everything is documented."
169    
170     BKB
171    
172     "[Deleted - thanks to Steffen Schwigon for pointing out this review was
173     in error.]"
174    
175     Somni
176    
177     "the arrogance of the guy"
178     "I swear he tacked somenoe else's name onto the module
179     just so he could use the royal 'we' in the documentation"
180    
181     dngor
182    
183     "Heh. '"<elmex at ta-sa.org>"' The quotes are semantic
184     distancing from that e-mail address."
185    
186     Jerad Pierce
187    
188     "Awful name (not a proper pragma), and the SYNOPSIS doesn't tell you
189     anything either. Nor is it clear what features have to do with "common
190     sense" or discipline."
191    
192     acme
193    
194     "THERE IS NO 'no common::sense'!!!! !!!! !!"
195    
196 root 1.12 apeiron (meta-comment)
197    
198     How about quoting this: get a clue, you fucktarded amoeba.
199    
200 root 1.1 =head1 AUTHOR
201    
202     Marc Lehmann <schmorp@schmorp.de>
203     http://home.schmorp.de/
204    
205 root 1.4 Robin Redeker, "<elmex at ta-sa.org>".
206    
207 root 1.1 =cut
208