Frenemies part 2: What a difference a (Perl) module makes

Last week I explored using the Inline::Perl5 module to port a short Perl script to Raku while still keeping its Perl dependencies. Over at the Dev.to community, Dave Cross pointed out that I could get a bit more bang for my buck by letting his Feed::Fi…


This content originally appeared on DEV Community and was authored by Mark Gardner

Last week I explored using the Inline::Perl5 module to port a short Perl script to Raku while still keeping its Perl dependencies. Over at the Dev.to community, Dave Cross pointed out that I could get a bit more bang for my buck by letting his Feed::Find do the heavy lifting instead of WWW::Mechanize’s more general-purpose parsing.

A little more MetaCPAN investigation yielded XML::Feed, also maintained by Dave, and it had the added benefit of obviating my need of XML::RSS by not only discovering feeds but also retrieving and parsing them. It also handles the Atom syndication format as well as RSS (hi daxim!). Putting it all together produces the following much shorter and clearer Perl:

And here’s the Raku version:

It’s even closer to Perl now, though it’s using the first routine rather than subscripting the @feeds array and leaving off the the $_ variable name when calling methods on it—less punctuation noise often aids readability. I also took a suggested exit idiom from Raku developer Elizabeth Mattijsen on Reddit to simplify the contortions I was going through to exit with a simple message and error code.

There are a couple of lessons here:

  • A little more effort in module shopping pays dividends in simpler code.
  • Get feedback from far and wide to help improve your code. If it’s for work and you can’t release as open-source, make sure your code review process covers readability and maintainability.

Cover image: “Frenemies” by Mr. T in DC is licensed under CC BY-ND 2.0


This content originally appeared on DEV Community and was authored by Mark Gardner


Print Share Comment Cite Upload Translate Updates
APA

Mark Gardner | Sciencx (2021-08-24T14:00:00+00:00) Frenemies part 2: What a difference a (Perl) module makes. Retrieved from https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/

MLA
" » Frenemies part 2: What a difference a (Perl) module makes." Mark Gardner | Sciencx - Tuesday August 24, 2021, https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/
HARVARD
Mark Gardner | Sciencx Tuesday August 24, 2021 » Frenemies part 2: What a difference a (Perl) module makes., viewed ,<https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/>
VANCOUVER
Mark Gardner | Sciencx - » Frenemies part 2: What a difference a (Perl) module makes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/
CHICAGO
" » Frenemies part 2: What a difference a (Perl) module makes." Mark Gardner | Sciencx - Accessed . https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/
IEEE
" » Frenemies part 2: What a difference a (Perl) module makes." Mark Gardner | Sciencx [Online]. Available: https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/. [Accessed: ]
rf:citation
» Frenemies part 2: What a difference a (Perl) module makes | Mark Gardner | Sciencx | https://www.scien.cx/2021/08/24/frenemies-part-2-what-a-difference-a-perl-module-makes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.