From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bernhard Bitsch To: development@lists.ipfire.org Subject: Aw: Re: [PATCH] Fix for bug 12539 Date: Thu, 10 Dec 2020 16:26:19 +0100 Message-ID: In-Reply-To: <54087019-8A43-4FB1-8811-8C1C8B4B2D86@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4127688370358323983==" List-Id: --===============4127688370358323983== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable > Gesendet: Donnerstag, 10. Dezember 2020 um 15:48 Uhr > Von: "Michael Tremer" > An: "Bernhard Bitsch" > Cc: "IPFire: Development-List" > Betreff: Re: [PATCH] Fix for bug 12539 > > Hello, >=20 > > On 10 Dec 2020, at 15:35, Bernhard Bitsch wrot= e: > >=20 > > Hi, > >=20 > >> Gesendet: Donnerstag, 10. Dezember 2020 um 14:29 Uhr > >> Von: "Michael Tremer" > >> An: "Bernhard Bitsch" > >> Cc: "Adolf Belka" , development(a)lists.ipfire.o= rg > >> Betreff: Re: [PATCH] Fix for bug 12539 > >>=20 > >> Hi, > >>=20 > >>> On 10 Dec 2020, at 14:13, Bernhard Bitsch wr= ote: > >>>=20 > >>> Hello, > >>>=20 > >>>> Gesendet: Donnerstag, 10. Dezember 2020 um 13:48 Uhr > >>>> Von: "Michael Tremer" > >>>> An: "Adolf Belka" > >>>> Cc: development(a)lists.ipfire.org > >>>> Betreff: Re: [PATCH] Fix for bug 12539 > >>>>=20 > >>>> Hello, > >>>>=20 > >>>> Great work. This looks like how it should be. > >>>>=20 > >>>>> On 7 Dec 2020, at 15:01, Adolf Belka wrote: > >>>>>=20 > >>>>> The installer recognises cups and cups-filters both as cups and puts > >>>>> two instances of cups in the add-on services table. > >>>>> Based on input from Michael Tremer this patch replaces the command > >>>>> returning the second element between hyphens with one that takes > >>>>> what comes after "meta-" using Perl code rather than a shell command. > >>>>> The second find command was changed as per Michael's suggestion. > >>>>>=20 > >>>>> Tested in my ipfire test bed system and only results in one cups > >>>>> entry. > >>>>> Signed-off-by: Adolf Belka > >>>>> --- > >>>>> html/cgi-bin/services.cgi | 9 +++++---- > >>>>> 1 file changed, 5 insertions(+), 4 deletions(-) > >>>>>=20 > >>>>> diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi > >>>>> index 26ab4f314..36954ba70 100644 > >>>>> --- a/html/cgi-bin/services.cgi > >>>>> +++ b/html/cgi-bin/services.cgi > >>>>> @@ -161,19 +161,20 @@ END > >>>>> my $lines=3D0; # Used to count the outputlines to make different bgc= olor > >>>>>=20 > >>>>> # Generate list of installed addon pak's > >>>>> - my @pak =3D `find /opt/pakfire/db/installed/meta-* 2>/dev/null | cu= t -d"-" -f2`; > >>>>> + opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot opendir /= opt/pakfire/db/installed/: $!"; > >>>>> + my @pak =3D sort readdir DIR; > >>>>> foreach (@pak){ > >>>>> chomp($_); > >>>>> + next unless (m/^meta-/); > >>>>> + s/^meta-//; > >>>>=20 > >>>> Although this is the least intuitive thing to do. I have no idea who d= esigned Perl. I hope they are proud of all the chaos they have created :) > >>>>=20 > >>>> -Michael > >>>=20 > >>> Can't see where the solution is 'least intuitive'. As far as I can see = from the patch, now the directory of installed addons is read with Perl funct= ions ( not in a extra forked process ). The definition of filenames is used c= onsequently ( 'meta-', possible services are stored in /etc/init.= d/ ). > >>=20 > >> To be clear, I am complaining about the Perl language design instead of = the code. In my view something like > >>=20 > >> name =3D name.replace(=E2=80=9Cmeta-=E2=80=9C, =E2=80=9C=E2=80=9D) > >>=20 > >> is a thousand times easier to read. > >>=20 > >> Best, > >> -Michael > >>=20 > >=20 > > Okay, that makes it clearer.=20 > > Perl has its roots in pattern matching. So the base functions of matching= and replacing are defined with minimal overhead in writing. > > Maybe the designer(s) of Perl had in mind the description of COBOL as "sp= eaking english with your computer". This was in the beginnings of computing, = which did not experience all of us. ;) > > With this single example you are right. Your formulation is much more rea= dable ( besides the fact that name is a string object ). But if you have many= such snippets in your code, the Perl way makes a shorter and thus more under= standable program. >=20 > I disagree. Why would the usage of something that is hard to comprehend be = better when it is being used more often? Getting used to the wrong pattern do= esn=E2=80=99t make it right. >=20 > My main complaint about this is, that it is not clear what is being manipul= ated. It is better to use the variable name and then there is no confusion ab= out it. The same is true for loads of other Perl-isms like shift, chomp, chop= , etc. >=20 > Shorter code does not necessarily mean that it executes faster. Probably th= e opposite is true in this case, because you would have to compile a regular = expression first and the Python version would simply perform a string search. >=20 > The point is, that code should be obvious. It avoids bugs and it makes it e= asier to understand for reviewers what is supposed to go on. >=20 The main difference between the Perl and the Python approach is the basic lan= guage class. Python works on objects and with their methods ( functions ), Pe= rl works on plain variables with operators. Types are determined by the opera= tor and context. Each operator has also a result which isn't destroyed by a a= ssigment or statement end. This result is hold in a special variable which ca= n be manipulated directly.=20 If I review code, I should know this basics. Thus it doesn't make a real diff= erence in comprehension ( to me ) if I read a object-oriented Python code or = a Perl code. Nevertheless is the Perl code shorter. In our special example Pe= rl avoids the generation (in written code ) of an intermeditiate variable by = use of the implicit $_. But this is a case of habit. Some like to talk in English only, some like to = talk in their native language to be more exact. ;) Best, Bernhard > Best, > -Michael >=20 > >=20 > > Best, > > Bernhard > >=20 > >>>=20 > >>> - Bernhard > >>>=20 > >>>=20 > >>>>=20 > >>>>>=20 > >>>>> # Check which of the paks are services > >>>>> - my @svc =3D `find /etc/init.d/$_ 2>/dev/null | cut -d"/" -f4`; > >>>>> - foreach (@svc){ > >>>>> + if (-e "/etc/init.d/$_") { > >>>>> # blacklist some packages > >>>>> # > >>>>> # alsa has trouble with the volume saving and was not really stopp= ed > >>>>> # mdadm should not stopped with webif because this could crash the= system > >>>>> # > >>>>> - chomp($_); > >>>>> if ( $_ eq 'squid' ) { > >>>>> next; > >>>>> } > >>>>> -- > >>>>> 2.29.2 >=20 > --===============4127688370358323983==--