Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] Working on repository

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: IKEDA Soji <address@concealed>
  • To: address@concealed
  • Subject: Re: [sympa-developpers] Working on repository
  • Date: Mon, 3 Mar 2014 13:29:29 +0900

Hi,

FYI.

On Wed, 26 Feb 2014 10:31:03 +0100
Guillaume Rousse <address@concealed> wrote:

<<snip>>

> The following example should adress the various concerns, and constitute
> a suitable *prefered* template for public functions/methods (ie: not the
> absolute rule):
>
> sub function {
> my (%params) = @_;
>
> if (!$params{c}) {
> # log error and return
> }
>
> $a = defined $params{a} ? $params{a} : 'default for A';
> $b = defined $params{b} ? $params{b} : 'default for B';
> $c = $params{c);
>
> ...
> }
>
> Is that acceptable for everyone ?

I rethought on it and found following way is possible:

sub function {
my $a = shift;
my $b = shift;
my %params = (
c => 'gamma',
d => 'delta',
@_
);

unless (test on $b succeed) {
# log error and return
}

...
}

then call it as:

# log error and return
function('alpha');

# same as function('alpha', 'beta', c => 'gamma', d => 'delta');
function('alpha', 'beta');

# same as function('alpha', 'beta', c => 'omega', d => 'delta');
function('alpha', 'beta', c => 'omega');

# same as function('alpha', 'beta', c => undef, d => 'delta');
function('alpha', 'beta', c => undef);

By this way, what options are available will be clear, optional
arguments always have defaults, and additionally, they may have
"undef" values.


Regards,

--- Soji

--
株式会社 コンバージョン セキュリティ&OSSソリューション部 池田荘児
〒231-0004 神奈川県横浜市中区元浜町3-21-2 ヘリオス関内ビル7F
e-mail address@concealed TEL 045-640-3550
http://www.conversion.co.jp/



Archive powered by MHonArc 2.6.19+.

Top of Page