Perl::...tBlock(3pm)

πŸ’– NAME πŸ’–

okay so bestie, this is the Perl::...tBlock(3pm) page from the User Contributed Perl Documentation, and it's all about Perl::Critic::Policy::BuiltinFunctions::ProhibitReverseSortBlock β€” aka the policy that says: Forbid $b before $a in sort blocks. periodt πŸ’…

πŸ¦‹ AFFILIATION πŸ¦‹

This Policy is part of the core Perl::Critic distribution. It's literally built in, no cap. 🫢

✨ DESCRIPTION ✨

Conway says it's much clearer to use reverse than to flip $a and $b around inside a sort block. He also suggests that, in newer perls, reverse is specifically looked for and optimized, and in the case of a simple reversed string sort, using reverse with a sort with no block is faster even in old perls. the way that's lowkey iconic ✨

Here's the vibe check β€” these are not ok vs ok:

    my @foo = sort { $b cmp $a } @bar;         #not ok
    my @foo = reverse sort @bar;               #ok

    my @foo = sort { $b <=> $a } @bar;         #not ok
    my @foo = reverse sort { $a <=> $b } @bar; #ok

πŸŽ€ CONFIGURATION πŸŽ€

This Policy is not configurable except for the standard options. That's it β€” no extra knobs, no secret settings. πŸŽ€

🌸 AUTHOR 🌸

Chris Dolan <cdolan@cpan.org> β€” yes, that's the author credit, bestie. 🌸

Copyright (c) 2006-2011 Chris Dolan.

The license tea: This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸ‘‘


Source/version + date, for the record: perl v5.42.0, dated 2024-10-23. Bye bestie, go make your sort blocks cute and correct πŸ’œβœ¨

πŸ“¦ where this page comes from