home.social

#perlcritic — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #perlcritic, aggregated by home.social.

fetched live
  1. Recently I learned that there is a #PerlCritic policy preventing you from confusing `eq` and `==` 🤯

    metacpan.org/pod/Perl::Critic:

    I often do have mixed feelings about learnings like this... on the one hand I am really happy that I learned something new and found something incredibly useful, on the other hand I feel seriously bad for not having already known about something this basic...

  2. @Pyrrhlin I like to see the test first when reading from left to right.

    Per #perlcritic I reserve postfix controls for program flow control functions like return, last, next, etc. metacpan.org/pod/Perl::Critic:

  3. @tripleo #Perl’s “sharp edges” are mainly early syntax and features that later experience with large and networked #programming found dangerous, but are preserved for backward (and we do mean “backward”) compatibility.

    See the details of the `strict` and `warnings` pragmas, and successively missing items in `feature` bundles:

    perldoc.perl.org/strict
    perldoc.perl.org/warnings
    perldoc.perl.org/feature#FEATU

    And the summary of policies included in #PerlCritic: MetaCPAN.org/pod/Perl::Critic:

  4. @Perl If you were at last year’s #Perl and Raku Conference in Toronto, you might have heard @davorg's talk on #GitHub Actions. He's recently released a set of reusable workflows for you to try in your projects: perlhacks.com/2024/01/github-a

    Right now you can run your tests on a variety of operating systems, check test coverage, and run #PerlCritic across your code. He's also working on #CPAN release and #DistZilla testing workflows.

    fosstodon.org/@davorg/11178871

  5. @nobodyinperson Bliss to write but not to read as tortuous double-negatives pile up with maintenance. The ProhibitUnlessBlocks #PerlCritic policy exists for a reason: metacpan.org/pod/Perl::Critic:

    This applies to both `unless` and `until`. Congratulations if you've used them in the past: you contributed to #Perl's reputation as a write-only language in the eyes of the person who had to revise your code to deal with more complicated conditions.

  6. @lemorin This also means you can disable the Modules::RequireNoMatchVarsWithUseEnglish #PerlCritic policy (metacpan.org/pod/Perl::Critic:) if you can be sure you’re running on #Perl v5.20 or later!

  7. @eliasp @ColinTheMathmo BTW #Perl has two well-known tools to encourage and enforce #programming style and best practices, respectively:
    #PerlTidy: perltidy.github.io/perltidy
    #PerlCritic: perlcritic.com

    Your project or team can use their reasonable defaults or further configure them to reflect and maintain the consistent application of your preferences. They also integrate with editors/IDEs, source control management, and author #testing.

  8. @dakkar @Perl `use v5.36;` or later will disable #Perl indirect object syntax.

    And the MetaCPAN.org/pod/Perl::Critic: policy will catch it.

    You mandate things by adding #PerlCritic to your tests or pre-commit hooks, not by relying on your team’s individual vigilance

  9. @ovid and other Perl :perl: mongers. What, if anything, do you use for code security?

    I know that using taint gets you far, but SAST is mostly what I’m thinking (especially for legacy code without taint). Any tips?

    Does Perl::Critic do a decent job, and is there a list of what its security policy and 3rd party plug-ins cover?

    Other OS SAST I found are: github.com/htrgouvea/zarn and this grep-based one: github.com/wireghoul/graudit

    Are they OK?

  10. @regehr @commodore @dev There is even a (low-severity, a/k/a “cruel”) #PerlCritic policy to discourage everything but $_, @_, $], and numbered #RegularExpression capture variables: metacpan.org/pod/Perl::Critic:

    metacpan.org/pod/Perl::Critic: already protects you against the performance-sapping $`, $&, and $' match variables

    And you can configure your own prohibited list with metacpan.org/pod/Perl::Critic:

    #Perl #RegEx #RegExp #RegExes #RegExps

  11. @rrwo Neat! TIL about the #Perl Sub::Util module and its `set_prototype` function: perldoc.perl.org/Sub::Util#set

    Did you switch to that in github.com/robrwo/Hash-Util-Me just to remove #PerlCritic noise, or was there another reason?

  12. @rbairwell @barubary Conway notes some problems with #Perl AUTOLOAD in “Perl Best Practices” (2005) and there is a severity 3 policy against it provided with #PerlCritic: metacpan.org/pod/Perl::Critic:

    Basic problems are: first AUTOLOAD wins in a class hierarchy; your AUTOLOAD has to handle/reject everything cleanly and is therefore an infinitely complex interface; AUTOLOAD gets called on object destruction if the class is missing an explicit DESTROY method

  13. @rrwo In my experience, functions that return scalars are much more common than functions that return multiple values (lists), so all else being equal, return undef; is much more likely to be correct than return; in a function that returns a value.

    I'm not a fan of the default #PerlCritic policies in general, but this one is just wrong.

  14. @jens @RL_Dane @stoerdebegga One reason I choose #Perl is its expressivity without being too “large” of a language. (This last is why I still haven’t wrapped my head around #RakuLang—they threw so much into its core.)

    I use #PerlCritic and #PerlTidy to set fairly strict defaults, but both have escape hatches for code islands that need to bend the rules for whatever reason (e.g. better modeling or critical-path performance, or sometimes fencing off legacy code to be brought up to spec later).

  15. @RL_Dane Hah. Great question. The default policies are based on a book by Damian Conway (Perl Best Practices), many of which I disagree with.¹ (In fact, I would recommend avoiding any Conway modules in your dependency chain.) So I don't think the perlcritic defaults are sane, but alternatives are available (e.g. metacpan.org/pod/Perl::Critic:).

    ¹ From what I recall, a central point of the book is that the policies are not a "one size fits all" solution, but that you should consciously evaluate each recommendation and whatever the result, write it down (along with your rationale). That way you end up with a useful and consistent style guide for your org, even if you disagree with every single recommendation.

    #perl #PerlCritic

  16. @RL_Dane @jens @stoerdebegga #PerlCritic is not a module you ordinarily use. It is a command you run: metacpan.org/dist/Perl-Critic/

    Or a test you incorporate via something like metacpan.org/pod/Test::Perl::C or metacpan.org/pod/Test2::Tools:.

    It would not make a lot of sense to require you to modify all your code to make sure it complies.

    Default is to only report severe violations from all installed policies. The core policies are summarized here: metacpan.org/dist/Perl-Critic/

  17. @RL_Dane @jens @stoerdebegga Opinions vary on how, but you should always check the return value of `open`. metacpan.org/pod/Perl::Critic: enforces that.

    I like autodie: perldoc.perl.org/autodie

    General consensus is that `unless` is confusing and postfix conditionals are too, except when used in flow control. metacpan.org/pod/Perl::Critic: and metacpan.org/pod/Perl::Critic: enforce that.

    Since opinions vary, codify your projects’ standards in #PerlCritic’s configuration to settle arguments: metacpan.org/pod/Perl::Critic#

  18. @jens @RL_Dane @stoerdebegga (I also think every #CPAN distribution should include #perltidy and #perlcritic configs and author tests to encourage consistently-written contributions.)

  19. @sjn @cb 99% of the “#Perl is line noise” complaints are because of unformatted #RegularExpressions. Every language worth anything eventually supports them, but only @Perl (and #awk, earlier) makes them first-class citizens. And with Perl you can format and comment them for readability: perldoc.perl.org/perlretut#Emb

    We format the rest of our code for humans. Why not #regexps?

    #PerlCritic can warn against bad regexps: metacpan.org/search?size=200&q

    #regex #regexes #programming #coding #SoftwareDevelopment

  20. @smxi @ChristosArgyrop Of course, there’s a #PerlCritic policy to slap you on the wrist if you’re tempted to do such a rude thing as automatically export into a caller’s namespace: metacpan.org/pod/Perl::Critic:

  21. @ChristosArgyrop @Perl In answer to your question about #Perl symbolic references on the Twitter community (twitter.com/ChristosArgyrop/st), I still find them useful when you want to dynamically define things in the symbol table like functions/methods. Though Package::Stash provides a nice API for that so you don’t have to litter your code with `no strict 'refs'` and attendant #PerlCritic annotations. metacpan.org/pod/Package::Stas

  22. @chrisjrob @snonux @Perl #PerlTidy and #PerlCritic also help with readable, maintainable, and consistent #Perl code. I like to joke that I don’t have a style, I have a perlcritic policy.

  23. @living8bit FWIW it’s bad form to use $a and $b for your own #Perl variables unless they’re local to a block. They’re magic inside a sort block perldoc.perl.org/functions/sor

    Here’s the relevant #PerlCritic policy: metacpan.org/pod/Perl::Critic:

  24. @PinkFreud @Perl Remember that I didn’t tell you about this, and if I did, I told you to use this #PerlCritic policy metacpan.org/pod/Perl::Critic: