[Nfsen-discuss] passing named parameters
Netflow visualisation and investigation tool
Brought to you by:
phaag
|
From: Kiss G. [Bitman] <ki...@ss...> - 2006-08-16 10:00:08
|
Dear Peter,
I suggest to change the parameter passing of library routines like
NfSenRRD::SetupRRD.
Now caller have set up several trivial params in fixed order:
NfSenRRD::SetupRRD("$NfConf::PROFILESTATDIR/live", $new_source,
$tstart - 300, 0);
Now I plan to add Holt-Winters forecasting into RRDs and probably
I'd will have other developments. This may make some parameter lists
long and messy therefore easy to get it wrong.
Hash-line named parameters are more readable:
NfSenRRD::SetupRRD(
path => "$NfConf::PROFILESTATDIR/live",
db => $new_source,
start => $tstart - 300,
# No 'force => 0' required because this is the default value
hw => 1, # add Holt-Winters
alpha => 0.4,
# Other optional parameters here
);
Then function's head could look like this:
sub SetupRRD {
my %args = @_;
my $path = $args{path};
my $db = $args{db};
my $start = $args{start};
my $hw = $args{hw}; # undef (=false) if missing
my $force = $args{force}; # undef (=false) if missing
my $alpha = $args{alpha} || 0.3;
my $beta = $args{beta} || 0.002;
my $gamma = $args{gamma} || 0.05;
What is your opinion?
Regards
Gabor
|