Perl::...sBlocks(3pm)

🌸 NAME 🌸

okay so bestie, welcome to Perl::...sBlocks(3pm) β€” that's the User Contributed Perl Documentation version of this page, and it's basically a whole policy about one tiny little word. So Perl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks β€” yeah it's a mouthful, we know β€” is the policy that tells you to write if(! $condition) instead of unless($condition). like, that's the whole thing. that's the vibe. ✨


πŸŽ€ AFFILIATION πŸŽ€

This Policy is part of the core Perl::Critic distribution. so like, it ships with the band, it's not a side project. it's core, it's main character energy, it was always invited to the party πŸ’…


πŸ’– DESCRIPTION πŸ’–

okay so Conway β€” yes, that Conway β€” discourages using unless because (and this is so real of him) it leads to double-negatives that are hard to understand. like your brain does a little backflip mid-sentence and lands on its face. instead, just reverse the logic and use if. slay. simple. iconic.

    unless($condition) { do_something() } #not ok
    unless(! $no_flag) { do_something() } #really bad
    if( ! $condition)  { do_something() } #ok

see that middle one? unless(! $no_flag)? that's not just not-ok, that's #really bad in the original's own words. two negations in a trenchcoat. we do not stan. the comments there are literally the original's, i'm not even being dramatic for once 😭

heads up: this Policy only covers the block-form of unless. the postfix variety is somebody else's problem β€” see ProhibitPostfixControls, which is linked down below in SEE ALSO 🫢

🌈 CONFIGURATION 🌈

This Policy is not configurable except for the standard options. that's it. no knobs, no dials, no secret settings. she is what she is and honestly? respect πŸŽ€


⭐ SEE ALSO ⭐

  • Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls β€” that's the postfix one, go say hi πŸ‘‹

πŸ‘‘ AUTHOR πŸ‘‘

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β€” the author! legendary. thank him, he made the policy that's about to roast your unless blocks πŸ’œ


Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.

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.

(read that again bestie: same terms as Perl itself, and if you want the whole legal spiel it's chilling in the LICENSE file that came with this module. no cap, go read it if you're curious 🌸)


and that's the whole page! πŸ’– fr fr, this is Perl::...sBlocks(3pm) from perl v5.42.0, dated 2024-10-23, straight out of the User Contributed Perl Documentation. mwah. go write some if(! ...) blocks and make Conway proud πŸ§šβœ¨πŸ“

πŸ“¦ where this page comes from