Skip to Content.
Sympa Menu

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

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Marc Chantreux <address@concealed>
  • To: David Verdin <address@concealed>
  • Cc: address@concealed
  • Subject: Re: [sympa-developpers] Working on repository
  • Date: Tue, 4 Mar 2014 14:16:00 +0100

On Wed, Feb 26, 2014 at 10:51:08AM +0100, David Verdin wrote:
> >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 ?
> You make a valid poiunt here. I tend to enforce a uniform style
> whereas a uniform good sense is often enough.


there (and as David told us about "template function"), i have a strong
opinion :)

> > $a = defined $params{a} ? $params{a} : 'default for A';
> > $b = defined $params{b} ? $params{b} : 'default for B';

* don't use special variables $a and $b even in exemples (as you don't
know what people do from your examples).
* what you want to say is setting defaut parameters there (and undef
*is* a value). please write:

$foo = exists $param{foo} ? $param{foo} : 'default';

(just a note): for readability (and when i don't nest them), i always
write my ternary operators multilined:

$foo = exists $param{foo}
? $param{foo}
: 'default';

in the case undef isn't a possible value, i use // (but it was
introduced in 5.10 AFAIK). so it leads me to

$foo = $param{foo} // 'default';

regards

--
Marc Chantreux
Université de Strasbourg, Direction Informatique
14 Rue René Descartes,
67084 STRASBOURG CEDEX
☎: 03.68.85.57.40
http://unistra.fr
"Don't believe everything you read on the Internet"
-- Abraham Lincoln



Archive powered by MHonArc 2.6.19+.

Top of Page