Perl::...erators(3pm)

🌸 Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators (3pm) 🌸

okay bestie, welcome to the User Contributed Perl Documentation page for Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators β€” that’s the manual name, and we’re in section 3pm, iykyk. πŸ’…


✨ NAME ✨

This policy is literally here to tell you: Write !$foo && $bar || $baz instead of not $foo && $bar or $baz. That’s the whole assignment. πŸŽ€


🫢 AFFILIATION 🫢

This Policy is part of the core Perl::Critic distribution. iconic, honestly. πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

Conway advises against combining the low-precedence booleans (and or not) with the high-precedence boolean operators (&& || !) in the same expression. Unless you fully understand the differences between the high and low-precedence operators, it is easy to misinterpret expressions that use both. And even if you do understand them, it is not always clear if the author actually intended it. the way that is such a real trap 😭

Here’s the vibe check:

    next if not $foo || $bar;  #not ok
    next if !$foo || $bar;     #ok
    next if !( $foo || $bar ); #ok

slay β€” see how the ok ones keep it clean? πŸ’…


πŸ’œ CONFIGURATION πŸ’œ

This Policy is not configurable except for the standard options. So no extra knobs, no secret settings β€” just the standard options, periodt. πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β€” shoutout to the author, main character energy fr fr. 🫢


Copyright (c) 2005-2023 Imaginative Software Systems

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. πŸ“œ


xoxo, bestie πŸ’– this page’s source/version is perl v5.42.0, dated 2024-10-23 β€” mwah 🫢

πŸ“¦ where this page comes from