Subject: Developers of Sympa
List archive
- From: "Stefan Hornburg (Racke)" <address@concealed>
- To: address@concealed
- Subject: [sympa-developpers] Sympa code critics DRY
- Date: Tue, 14 May 2019 17:16:36 +0200
Hello,
while looking at the code relevant for #613 I found a code pattern that seems
to repeat in the Sympa code:
# Check for a match in subject
if (($self->subj) && ($_ = $subj) && (&{$self->{function2}})) {
$subj =~ s,($self->{key_word}),\001$1\002,g; # Bold any matches
$self->subj_count(1); # Keeping count
$match = 1; # We'll be printing this one
}
# Check for a match in from
if (($self->from) && ($_ = $from) && (&{$self->{function2}})) {
$from =~ s,($self->{key_word}),\001$1\002,g;
$self->from_count(1);
$match = 1;
}
# Check for a match in date
if (($self->date) && ($_ = $date) && (&{$self->{function2}})) {
$date =~ s,($self->{key_word}),\001$1\002,g;
$self->date_count(1);
$match = 1;
}
# Check for a match in id
if (($self->id) && ($_ = $id) && (&{$self->{function2}})) {
$id =~ s,($self->{key_word}),\001$1\002,g;
$self->id_count(1);
$match = 1;
}
It basically uses the same thing in every four cases - so that definitely
defies the DRY principle. I saw the
same thing in other places of Sympa with variables like $subj, $from, $date,
$id.
In both cases it should be possible to loop over the variables / methods and
use only one code block.
On top of that I have no clue what the heck is in $_ when looking at this
code.
Regards
Racke
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.
Attachment:
signature.asc
Description: OpenPGP digital signature
- [sympa-developpers] Sympa code critics DRY, Stefan Hornburg (Racke), 05/14/2019
Archive powered by MHonArc 2.6.19+.