Perl::...iltins(3pm)

πŸ’… NAME

Okay bestie, so this page is Perl::...iltins(3pm) β€” a User Contributed Perl Documentation page, no big deal β€” and the actual policy it's describing is Perl::Critic::Policy::CodeLayout::ProhibitParensWithBuiltins, which basically screams at you to write open $handle, $path instead of open($handle, $path). That's the whole vibe. ✨


🫢 AFFILIATION

This Policy is part of the core Perl::Critic distribution. So like, it ships with the thing, you don't gotta go hunting. πŸŽ€


🌸 DESCRIPTION

So Conway (yes, that Conway) suggests that all built-in functions should be called without parentheses around the argument list. It's giving minimalism. It reduces visual clutter and it disambiguates built-in functions from user functions β€” which honestly? Iconic. πŸ”₯

There are exceptions though: my, local, and our are the special little guys that require parentheses when called with multiple arguments.

open($handle, '>', $filename); #not ok
open $handle, '>', $filename;  #ok

split(/$pattern/, @list); #not ok
split /$pattern/, @list;  #ok

See how much cleaner that is without the parens? The way the second one in each pair just breathes. πŸ’–


✨ CONFIGURATION

This Policy is not configurable except for the standard options. That's it, that's the whole tea. πŸ“


πŸ’œ NOTES

Lowkey important one here: coding with parentheses can sometimes lead to verbose and awkward constructs, so the author thinks the intent of Conway's guideline is to remove only the unnecessary parentheses. Makes sense, right? 🧚

So this policy makes exceptions for some common situations where parentheses are usually required. But β€” and this is the "listen bestie" part β€” you may find other situations where the parentheses are necessary to enforce precedence, but they still cause violations. Awkward. 😭 In those cases, consider using the ## no critic comments to silence Perl::Critic. Saved your life fr fr. 🫢


πŸ’€ BUGS

Some builtin functions (particularly those that take a variable number of scalar arguments) should probably get parentheses. Yeah. πŸ™ˆ

This policy should be enhanced to allow the user to specify a list of builtins that are exempt from the policy β€” but as of right now, it doesn't. No cap.


πŸ‘‘ AUTHOR

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β€” the main character who made this. 🌈


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. πŸ“œ


πŸ¦‹ Written by perl, version v5.42.0, dated 2024-10-23, and this page you just read is Perl::...iltins(3pm). Slay, go forth and delete those unnecessary parentheses πŸ’…βœ¨
πŸ“¦ where this page comes from