Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jN7mi-0005V4-Ph for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Apr 2020 04:30:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jN7mg-0007D5-39 for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Apr 2020 04:30:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jN7mf-0007Cy-SM for pgsql-hackers@lists.postgresql.org; Sat, 11 Apr 2020 04:30:21 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jN7md-0003zv-F9 for pgsql-hackers@postgresql.org; Sat, 11 Apr 2020 04:30:20 +0000 Received: by mail-pf1-x443.google.com with SMTP id a13so1927232pfa.2 for ; Fri, 10 Apr 2020 21:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=d1+wk2+//vnIAE4iMGmxffafVWHAu3E87LvBLrGtPyc=; b=coDGyXvs5cu/Ulvt01M5aRI9M3OCPXJzcKaFE7KL5a2cA7w3rpLl9bCVenzmRUMXZn I+EiVdipfajoEQ4GESOLkxAMO1sHrQ0D5oka914LLvs2EnulZVz1ONk4vwk75JBepeQy aztmWOwYGL6s4wAAQ62kdDYUJLzvFSjwYH3uE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=d1+wk2+//vnIAE4iMGmxffafVWHAu3E87LvBLrGtPyc=; b=aqE03Fm6om7Wdb/kgVt7hCqpP2oww6xSjrGEBcYZ/GUs4dnOap4VCBTk82ldIlvNvQ iTIJUsTmKetgMbWEVXiETwsM8oW1pb1sTs+V+4HYsYpf30k0KCzWXuyBw9B/eD8tjk11 g3rAmyqC7WGjjoz5XukgtSONQE6aro5FzDJI9f8QTg7pAopAOCaFLhqFsh/XQsfPOA2Q 8r0LGzx+WWkB9JeNsesVm4iOv3NiWTqfbI+ic/01RZKBMgm9/XgHWQinRE+c1zHRT1AW LqxxHx6pMLTlsEpzfzbIG3tQwxzGxk7rTi8IcO3abuOxQuGhbwo9hofkj9bgQ32C3EaD 04hQ== X-Gm-Message-State: AGi0PuacUpNwpsnGAaeEVFBUZEcIr6S9NyWTU8P3IvQSuBqX71ZvCx+t GF0osQaGKrRkP33xuZJ/MUJJvQ== X-Google-Smtp-Source: APiQypLE8IwPYTAGxalSdXvD6s1LDFS7qVdI9XJfWS4ZYWhjtVgl/ANnG1vXV7qyH0hej/7szzhRMA== X-Received: by 2002:aa7:8bd1:: with SMTP id s17mr8048847pfd.225.1586579417803; Fri, 10 Apr 2020 21:30:17 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id x15sm3141141pfq.107.2020.04.10.21.30.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Apr 2020 21:30:16 -0700 (PDT) Date: Sat, 11 Apr 2020 04:30:14 +0000 From: Noah Misch To: Andrew Dunstan Cc: PostgreSQL-development Subject: Re: cleaning perl code Message-ID: <20200411043014.GA590991@rfd.leadboat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Apr 09, 2020 at 11:44:11AM -0400, Andrew Dunstan wrote: >      39 Always unpack @_ first Requiring a "my @args = @_" does not improve this code: sub CreateSolution { ... if ($visualStudioVersion eq '12.00') { return new VS2013Solution(@_); } >      30 Code before warnings are enabled Sounds good. We already require "use strict" before code. Requiring "use warnings" in the exact same place does not impose much burden. >      12 Subroutine "new" called using indirect syntax No, thanks. "new VS2013Solution(@_)" and "VS2013Solution->new(@_)" are both fine; enforcing the latter is an ongoing waste of effort. >       9 Multiple "package" declarations This is good advice if you're writing for CPAN, but it would make PostgreSQL code worse by having us split affiliated code across multiple files. >       9 Expression form of "grep" No, thanks. I'd be happier with the opposite, requiring grep(/x/, $arg) instead of grep { /x/ } $arg. Neither is worth enforcing. >       7 Symbols are exported by default This is good advice if you're writing for CPAN. For us, it just adds typing. >       5 Warnings disabled >       4 Magic variable "$/" should be assigned as "local" >       4 Comma used to separate statements >       2 Readline inside "for" loop >       2 Pragma "constant" used >       2 Mixed high and low-precedence booleans >       2 Don't turn off strict for large blocks of code >       1 Magic variable "@a" should be assigned as "local" >       1 Magic variable "$|" should be assigned as "local" >       1 Magic variable "$\" should be assigned as "local" >       1 Magic variable "$?" should be assigned as "local" >       1 Magic variable "$," should be assigned as "local" >       1 Magic variable "$"" should be assigned as "local" >       1 Expression form of "map" I looked less closely at the rest, but none give me a favorable impression. In summary, among those warnings, I see non-negative value in "Code before warnings are enabled" only. While we're changing this, I propose removing Subroutines::RequireFinalReturn. Implicit return values were not a material source of PostgreSQL bugs, yet we've allowed this to litter our code: $ find src -name '*.p[lm]'| xargs grep -n '^.return;' | wc -l 194