… | |
… | |
18 | two typical (or not so typical - use your common sense) specimens of |
18 | two typical (or not so typical - use your common sense) specimens of |
19 | Perl coders. |
19 | Perl coders. |
20 | |
20 | |
21 | =over 4 |
21 | =over 4 |
22 | |
22 | |
|
|
23 | =item no warnings |
|
|
24 | |
|
|
25 | The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even |
|
|
26 | though we don't care if other people use warnings (and certainly there are |
|
|
27 | useful ones), a lot of warnings simply go against the spirit of Perl, most |
|
|
28 | prominently, the warnings related to C<undef>. There is nothing wrong with |
|
|
29 | C<undef>: it has well-defined semantics, it is useful, and spitting out |
|
|
30 | warnings you never asked for is just evil. |
|
|
31 | |
|
|
32 | 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. |
|
|
34 | |
|
|
35 | Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a |
|
|
36 | favourable way), but standard utilities, such as L<prove>, or MakeMaker |
|
|
37 | when running C<make test> enable them blindly. |
|
|
38 | |
23 | =item use strict qw(subs vars) |
39 | =item use strict qw(subs vars) |
24 | |
40 | |
25 | Using C<use strict> is definitely common sense, but C<use strict |
41 | Using C<use strict> is definitely common sense, but C<use strict |
26 | 'refs'> definitely overshoots it's usefulness. After almost two |
42 | 'refs'> definitely overshoots it's usefulness. After almost two |
27 | decades of Perl hacking, we decided that it does more harm than being |
43 | decades of Perl hacking, we decided that it does more harm than being |
28 | useful. Specifically, constructs like these: |
44 | useful. Specifically, constructs like these: |
29 | |
45 | |
30 | @{ $var->[0] } |
46 | @{ $var->[0] } |
31 | |
47 | |
32 | Must be written like this, when C<use strict 'refs'> is in scope, and |
48 | Must be written like this (or similarly), when C<use strict 'refs'> is in |
33 | C<$var> can legally be C<undef>: |
49 | scope, and C<$var> can legally be C<undef>: |
34 | |
50 | |
35 | @{ $var->[0] || [] } |
51 | @{ $var->[0] || [] } |
36 | |
52 | |
37 | This is annoying, and doesn't shield against obvious mistakes such as |
53 | This is annoying, and doesn't shield against obvious mistakes such as |
38 | using C<"">, so one would even have to write: |
54 | using C<"">, so one would even have to write: |
… | |
… | |
53 | something breaks because it didn't anticipate future changes, so be |
69 | something breaks because it didn't anticipate future changes, so be |
54 | it. 5.10 broke almost all our XS modules and nobody cared either - and few |
70 | it. 5.10 broke almost all our XS modules and nobody cared either - and few |
55 | modules that are no longer maintained work with newer versions of Perl, |
71 | modules that are no longer maintained work with newer versions of Perl, |
56 | regardless of use feature. |
72 | regardless of use feature. |
57 | |
73 | |
58 | If your code isn'talive, it's dead, jim. |
74 | If your code isn't alive, it's dead, jim. |
59 | |
|
|
60 | =item no warnings |
|
|
61 | |
|
|
62 | The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even |
|
|
63 | though we don't care if other people use warnings (and certainly there are |
|
|
64 | useful ones), a lot of warnings simply go against the spirit of Perl, most |
|
|
65 | prominently, the warnings related to C<undef>. There is nothing wrong with |
|
|
66 | C<undef>: it has well-defined semantics, it is useful, and spitting out |
|
|
67 | warnings you never asked for is just evil. |
|
|
68 | |
|
|
69 | So every module needs C<no warnings> to avoid somebody accidentally using |
|
|
70 | C<-w> and forcing his bad standards on our code. No will do. |
|
|
71 | |
|
|
72 | (Also, why isn't this a C<use feature> switch? Adding warnings is |
|
|
73 | apparently considered O.K., even if it breaks your programs). |
|
|
74 | |
75 | |
75 | =item much less memory |
76 | =item much less memory |
76 | |
77 | |
77 | Just using all those pragmas together waste <blink>I<< B<776> kilobytes |
78 | Just using all those pragmas together waste <blink>I<< B<776> kilobytes |
78 | |
|
|
79 | >></blink> of precious memory in my perl, for I<every single perl process |
79 | >></blink> of precious memory in my perl, for I<every single perl process |
80 | |
|
|
81 | using our code>, which on our machines, is a lot. In comparison, this |
80 | using our code>, which on our machines, is a lot. In comparison, this |
82 | module only uses I<< B<four> >> kilobytes (I even had to write it out so |
81 | module only uses I<< B<four> >> kilobytes (I even had to write it out so |
83 | it looks like more) of memory on the same platform. |
82 | it looks like more) of memory on the same platform. |
84 | |
83 | |
85 | The money/time/effort/electricity invested in these gigabytes (probably |
84 | The money/time/effort/electricity invested in these gigabytes (probably |
… | |
… | |
103 | $^H{feature_switch} = |
102 | $^H{feature_switch} = |
104 | $^H{feature_say} = |
103 | $^H{feature_say} = |
105 | $^H{feature_state} = 1; |
104 | $^H{feature_state} = 1; |
106 | } |
105 | } |
107 | |
106 | |
108 | =cut |
|
|
109 | |
|
|
110 | 1; |
107 | 1; |
111 | |
108 | |
112 | =back |
109 | =back |
|
|
110 | |
|
|
111 | =head1 NO 'no common::sense' |
|
|
112 | |
|
|
113 | This module doesn't offer an unimport. First of all, it wastes even more |
|
|
114 | memory, second, and more importantly, who with even a bit of common sense |
|
|
115 | would want no common sense? |
113 | |
116 | |
114 | =head1 AUTHOR |
117 | =head1 AUTHOR |
115 | |
118 | |
116 | Marc Lehmann <schmorp@schmorp.de> |
119 | Marc Lehmann <schmorp@schmorp.de> |
117 | http://home.schmorp.de/ |
120 | http://home.schmorp.de/ |
118 | |
121 | |
|
|
122 | Robin Redeker, "<elmex at ta-sa.org>". |
|
|
123 | |
|
|
124 | |
119 | =cut |
125 | =cut |
120 | |
126 | |