Subject: Developers of Sympa
List archive
- From: Guillaume Rousse <address@concealed>
- To: address@concealed
- Subject: Re: [sympa-developpers] ugly code 2
- Date: Tue, 23 Jul 2013 10:16:49 +0200
Le 23/07/2013 05:40, IKEDA Soji a écrit :
Hi,Instanciation will just help using the right tool for this job, as a class is supposed to be stateless.
Our s**tting router hung-up in this weekend, so I began to watch
merges yesterday.
On Mon, 22 Jul 2013 15:03:21 +0200
Guillaume Rousse <address@concealed> wrote:
## getter for internal config parameters.
croak "Can't call method \"$attr\" on uninitialized $self class"
unless $Sympa::Site::is_initialized;
If you need initialisation, it means you need a state. If you need a
state, you need a instance, not a class with global parameters.
As I guess the point is to share a single instance of Sympa::Site around
the code, you'd better create it once for all in top-level code, and
make it accessible as a global variable:
# top-level code
our $site = Sympa::Site->new();
$site->load();
# another part of code
package Sympa::FooBar;
$main::site->get_foo();
That's what I'm currently trying to do with database object, for instance.
The croak line shown is for impossible cases: If it occurred, it is a
bug.
After succeeding merges, $Sympa::Site::is_initialized will be
referred by Sympa::Log and Sympa::Language. Because those modules
must work even when site parameters had not been loaded: In such
case they use hardcoded defaults.
I feel this is ugry, too, but instantiation won't help.
$object->is_initialized() is OK.
Class->is_initialized() is not.
$Class::initialized is not.
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31
Attachment:
smime.p7s
Description: Signature cryptographique S/MIME
-
[sympa-developpers] ugly code 2,
Guillaume Rousse, 07/22/2013
-
Re: [sympa-developpers] ugly code 2,
IKEDA Soji, 07/23/2013
- Re: [sympa-developpers] ugly code 2, Guillaume Rousse, 07/23/2013
-
Re: [sympa-developpers] ugly code 2,
IKEDA Soji, 07/23/2013
Archive powered by MHonArc 2.6.19+.