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.10 by root, Tue Aug 18 00:47:16 2009 UTC vs.
Revision 1.11 by root, Sat Aug 22 20:21:29 2009 UTC

20 20
21=over 4 21=over 4
22 22
23=item no warnings 23=item no warnings
24 24
25The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even 25Ah, the dreaded warnings. Even worse, the horribly dreaded C<-w>
26though we don't care if other people use warnings (and certainly there are 26switch: Even though we don't care if other people use warnings (and
27useful ones), a lot of warnings simply go against the spirit of Perl, most 27certainly there are useful ones), a lot of warnings simply go against the
28spirit of Perl.
29
28prominently, the warnings related to C<undef>. There is nothing wrong with 30Most prominently, the warnings related to C<undef>. There is nothing wrong
29C<undef>: it has well-defined semantics, it is useful, and spitting out 31with C<undef>: it has well-defined semantics, it is useful, and spitting
30warnings you never asked for is just evil. 32out warnings you never asked for is just evil.
31 33
32So every module needs C<no warnings> to avoid somebody accidentally using 34So every module needs C<no warnings> to avoid somebody accidentally using
33C<-w> and forcing his bad standards on our code. No will do. 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.
34 37
35Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a 38Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a
36favourable way), but standard utilities, such as L<prove>, or MakeMaker 39favourable way), but standard utilities, such as L<prove>, or MakeMaker
37when running C<make test> enable them blindly. 40when running C<make test> enable them blindly.
38 41
39=item use strict qw(subs vars) 42=item use strict qw(subs vars)
40 43
41Using C<use strict> is definitely common sense, but C<use strict 44Using C<use strict> is definitely common sense, but C<use strict
42'refs'> definitely overshoots it's usefulness. After almost two 45'refs'> definitely overshoots its usefulness. After almost two
43decades 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
44useful. Specifically, constructs like these: 47useful. Specifically, constructs like these:
45 48
46 @{ $var->[0] } 49 @{ $var->[0] }
47 50
49scope, and C<$var> can legally be C<undef>: 52scope, and C<$var> can legally be C<undef>:
50 53
51 @{ $var->[0] || [] } 54 @{ $var->[0] || [] }
52 55
53This is annoying, and doesn't shield against obvious mistakes such as 56This is annoying, and doesn't shield against obvious mistakes such as
54using C<"">, so one would even have to write: 57using C<"">, so one would even have to write (at least for the time
58being):
55 59
56 @{ defined $var->[0] ? $var->[0] : [] } 60 @{ defined $var->[0] ? $var->[0] : [] }
57 61
58... which nobody with a bit of common sense would consider 62... which nobody with a bit of common sense would consider
63writing.
64
59writing. Curiously enough, sometimes, perl is not so strict, as this works 65Curiously enough, sometimes perl is not so strict, as this works even with
60even with C<use strict> in scope: 66C<use strict> in scope:
61 67
62 for (@{ $var->[0] }) { ... 68 for (@{ $var->[0] }) { ...
63 69
64If that isnt hipocrasy! And all that from a mere program! 70If that isn't hipocrasy! And all that from a mere program!
65 71
66=item use feature qw(say state given) 72=item use feature qw(say state given)
67 73
68We 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
69something breaks because it didn't anticipate future changes, so be 75something breaks because it didn't anticipate future changes, so be
70it. 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
71modules that are no longer maintained work with newer versions of Perl, 80Few modules that are not actively maintained work with newer versions of
72regardless 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.
73 83
74If your code isn't alive, it's dead, jim. 84If your code isn't alive, it's dead, jim - be an active maintainer.
75 85
76=item much less memory 86=item mucho reduced memory usage
77 87
78Just using all those pragmas together wastes <blink>I<< B<776> kilobytes 88Just using all those pragmas mentioned in the SYNOPSIS together wastes
79>></blink> of precious memory in my perl, for I<every single perl process 89<blink>I<< B<776> kilobytes >></blink> of precious memory in my perl, for
80using our code>, which on our machines, is a lot. In comparison, this 90I<every single perl process using our code>, which on our machines, is a
81module only uses I<< B<four> >> kilobytes (I even had to write it out so 91lot. In comparison, this module only uses I<< B<four> >> kilobytes (I even
82it looks like more) of memory on the same platform. 92had to write it out so it looks like more) of memory on the same platform.
83 93
84The money/time/effort/electricity invested in these gigabytes (probably 94The money/time/effort/electricity invested in these gigabytes (probably
85petabytes globally!) of wasted memory could easily save 42 trees, and a 95petabytes globally!) of wasted memory could easily save 42 trees, and a
86kitten! 96kitten!
87 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
88=cut 101=cut
89 102
90package common::sense; 103package common::sense;
91 104
92our $VERSION = '0.04'; 105our $VERSION = '1.0';
93 106
94sub import { 107sub import {
95 # no warnings 108 # no warnings
96 ${^WARNING_BITS} ^= ${^WARNING_BITS}; 109 ${^WARNING_BITS} ^= ${^WARNING_BITS};
97 110
124Most likely, we will pick a few useful warnings, instead of just disabling 137Most likely, we will pick a few useful warnings, instead of just disabling
125all of them. And maybe we will load some nifty modules that try to emulate 138all of them. And maybe we will load some nifty modules that try to emulate
126C<say> or so with perls older than 5.10 (this module, of course, should 139C<say> or so with perls older than 5.10 (this module, of course, should
127work with older perl versions - supporting 5.8 for example is just common 140work with older perl versions - supporting 5.8 for example is just common
128sense at this time. Maybe not in the future, but of course you can trust 141sense at this time. Maybe not in the future, but of course you can trust
129our common sense). 142our common sense to be consistent with, uhm, our opinion).
130 143
131
132=head1 WHAT OTHER PEOPLE HAVE TO SAY ABOUT THIS MODULE 144=head1 WHAT OTHER PEOPLE HAD TO SAY ABOUT THIS MODULE
145
146apeiron
147
148 "... wow"
149 "I hope common::sense is a joke."
150
151crab
152
153 "i wonder how it would be if joerg schilling wrote perl modules."
154
155H.Merijn Brand
156
157 "Just one more reason to drop JSON::XS from my distribution list"
133 158
134Pista Palo 159Pista Palo
135 160
136 "Something in short supply these days..." 161 "Something in short supply these days..."
137 162
166 191
167acme 192acme
168 193
169 "THERE IS NO 'no common::sense'!!!! !!!! !!" 194 "THERE IS NO 'no common::sense'!!!! !!!! !!"
170 195
171crab
172
173 "i wonder how it would be if joerg schilling wrote perl modules."
174
175H.Merijn Brand
176
177 "Just one more reason to drop JSON::XS from my distribution list"
178
179apeiron
180
181 "... wow"
182 "I hope common::sense is a joke."
183
184=head1 AUTHOR 196=head1 AUTHOR
185 197
186 Marc Lehmann <schmorp@schmorp.de> 198 Marc Lehmann <schmorp@schmorp.de>
187 http://home.schmorp.de/ 199 http://home.schmorp.de/
188 200

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines