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.1 by root, Thu Jul 9 16:14:16 2009 UTC vs.
Revision 1.4 by root, Thu Jul 9 17:58:11 2009 UTC

18two typical (or not so typical - use your common sense) specimens of 18two typical (or not so typical - use your common sense) specimens of
19Perl coders. 19Perl coders.
20 20
21=over 4 21=over 4
22 22
23=item no warnings
24
25The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even
26though we don't care if other people use warnings (and certainly there are
27useful ones), a lot of warnings simply go against the spirit of Perl, most
28prominently, the warnings related to C<undef>. There is nothing wrong with
29C<undef>: it has well-defined semantics, it is useful, and spitting out
30warnings you never asked for is just evil.
31
32So every module needs C<no warnings> to avoid somebody accidentally using
33C<-w> and forcing his bad standards on our code. No will do.
34
35Funnily enough, L<perllexwarn> explicitly mentions C<-w> (and not in a
36favourable way), but standard utilities, such as L<prove>, or MakeMaker
37when running C<make test> enable them blindly.
38
23=item use strict qw(subs vars) 39=item use strict qw(subs vars)
24 40
25Using C<use strict> is definitely common sense, but C<use strict 41Using 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
27decades of Perl hacking, we decided that it does more harm than being 43decades of Perl hacking, we decided that it does more harm than being
28useful. Specifically, constructs like these: 44useful. Specifically, constructs like these:
29 45
30 @{ $var->[0] } 46 @{ $var->[0] }
31 47
32Must be written like this, when C<use strict 'refs'> is in scope, and 48Must be written like this (or similarly), when C<use strict 'refs'> is in
33C<$var> can legally be C<undef>: 49scope, and C<$var> can legally be C<undef>:
34 50
35 @{ $var->[0] || [] } 51 @{ $var->[0] || [] }
36 52
37This is annoying, and doesn't shield against obvious mistakes such as 53This is annoying, and doesn't shield against obvious mistakes such as
38using C<"">, so one would even have to write: 54using C<"">, so one would even have to write:
53something breaks because it didn't anticipate future changes, so be 69something breaks because it didn't anticipate future changes, so be
54it. 5.10 broke almost all our XS modules and nobody cared either - and few 70it. 5.10 broke almost all our XS modules and nobody cared either - and few
55modules that are no longer maintained work with newer versions of Perl, 71modules that are no longer maintained work with newer versions of Perl,
56regardless of use feature. 72regardless of use feature.
57 73
58If your code isn'talive, it's dead, jim. 74If your code isn't alive, it's dead, jim.
59
60=item no warnings
61
62The dreaded warnings. Even worse, the horribly dreaded C<-w> switch. Even
63though we don't care if other people use warnings (and certainly there are
64useful ones), a lot of warnings simply go against the spirit of Perl, most
65prominently, the warnings related to C<undef>. There is nothing wrong with
66C<undef>: it has well-defined semantics, it is useful, and spitting out
67warnings you never asked for is just evil.
68
69So every module needs C<no warnings> to avoid somebody accidentally using
70C<-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
73apparently considered O.K., even if it breaks your programs).
74 75
75=item much less memory 76=item much less memory
76 77
77Just using all those pragmas together waste <blink>I<< B<776> kilobytes 78Just using all those pragmas together waste <blink>I<< B<776> kilobytes
78>></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
79using our code>, which on our machines, is a lot. 80using our code>, which on our machines, is a lot. In comparison, this
81module only uses I<< B<four> >> kilobytes (I even had to write it out so
82it looks like more) of memory on the same platform.
80 83
81The money/time/effort/electricity invested in these gigabytes (probably 84The money/time/effort/electricity invested in these gigabytes (probably
82petabytes globally!) of wasted memory could easily save 42 trees, and a 85petabytes globally!) of wasted memory could easily save 42 trees, and a
83kitten! 86kitten!
84 87
85=cut 88=cut
86 89
87package Async::Interrupt; 90package common::sense;
88 91
89no warnings; 92our $VERSION = '0.03';
90 93
91BEGIN { 94sub import {
92 $VERSION = '0.03'; 95 # no warnings
96 ${^WARNING_BITS} ^= ${^WARNING_BITS};
93 97
94 require XSLoader; 98 # use strict vars subs
95 XSLoader::load Async::Interrupt::, $VERSION; 99 $^H |= 0x00000600;
100
101 # use feature
102 $^H{feature_switch} =
103 $^H{feature_say} =
104 $^H{feature_state} = 1;
96} 105}
97
98our $DIED = sub { warn "$@" };
99
100=cut
101 106
1021; 1071;
103 108
104=back 109=back
105 110
106=head1 EXAMPLE 111=head1 NO 'no common::sense'
107 112
108There really should be a complete C/XS example. Bug me about it. 113This module doesn't offer an unimport. First of all, it wastes even more
109 114memory, second, and more importantly, who with even a bit of common sense
110=head1 IMPLEMENTATION DETAILS AND LIMITATIONS 115would want no common sense?
111
112This module works by "hijacking" SIGKILL, which is guaranteed to be always
113available in perl, but also cannot be caught, so is always available.
114
115Basically, this module fakes the receive of a SIGKILL signal and
116then catches it. This makes normal signal handling slower (probably
117unmeasurably), but has the advantage of not requiring a special runops nor
118slowing down normal perl execution a bit.
119
120It assumes that C<sig_atomic_t> and C<int> are both exception-safe to
121modify (C<sig_atomic_> is used by this module, and perl itself uses
122C<int>, so we can assume that this is quite portable, at least w.r.t.
123signals).
124 116
125=head1 AUTHOR 117=head1 AUTHOR
126 118
127 Marc Lehmann <schmorp@schmorp.de> 119 Marc Lehmann <schmorp@schmorp.de>
128 http://home.schmorp.de/ 120 http://home.schmorp.de/
129 121
122 Robin Redeker, "<elmex at ta-sa.org>".
123
124
130=cut 125=cut
131 126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines