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