Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118414 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60535 invoked from network); 11 Aug 2022 13:08:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Aug 2022 13:08:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9EC64180539 for ; Thu, 11 Aug 2022 08:10:30 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 11 Aug 2022 08:10:30 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id v3so21765671wrp.0 for ; Thu, 11 Aug 2022 08:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=pJReFivDTjGj5KsdUDNJbrm9ZRjFTJLGZuHSJiolee8=; b=IJqtZRQ3iZT3fqTQLOlMkFHZAznggoToGdTwX47zyo8ZwJIC7uM8N6EB1XgfChiv07 0sMaLHTc1Bev91PFruVR66+BnmMUkktl1TVNSMKoDgOtvu8n0gChS5xcP/d8BwdrWvI+ usyTLldJ5KBzhme72m2N9vZmVKNkf/zfQ7gQNC+hb6Ivo+pdWtuVtXuupoPsJl/NEXwB XkcK8Pqu9KaANE0pXvL7ypV1qeGEuVsa1vJu1Th7LQiSgD1DlCtdQ1TirVpxnzO54Zur +0RfzEM1REAZuY5VGyaISOsdoTV9HuEXSVZk4ro5zUALa/CRZF5MeXEtITt962aDn4Cf u/Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=pJReFivDTjGj5KsdUDNJbrm9ZRjFTJLGZuHSJiolee8=; b=LJQ9uRduhr97jqHFPpGeBnQfpavOWnB6gTdumHSwXeQr2bGKo5R3m8Zk/AiSDX/iR1 GmbNkAuqnGgKsv7ZRXz6AU5goFO9ZHRn8Zj0MNEAaUikmFWpWzJJxEm8z8fhgo4YNw1z LEH35X1b94mJKS2+GCiapzpe22PGnB9N8cDynokzx8YYsAyWbkxLwVBWTQHZGUgHhxOP CHy3OBmsUEjY1mstyeha/HImF9pJCW/evBBpWcJqSGaMSuRErq3311Jqp7a7o9KEVmcK SzSWNOTQa7WpAS8vl3fzjtFvy71IsxhHEbnSBSS8dnfgmMlemus5CU6Nt+4XLNa6RGhT cQ2g== X-Gm-Message-State: ACgBeo0gklfAPLUeuq8wcJSl9FlMaYnA2cUMGoN/6jPdT0AbKEJn7ba4 bNXNKd8o6rPsMD7EH4JyQsFWASPqfxU= X-Google-Smtp-Source: AA6agR6jpdU2jesdrnSEaZSzm+VFYwyBSXprEAZMpmoIzd3zFpios1uT7BP1lpNdjrenzdekuOgRpA== X-Received: by 2002:a5d:434a:0:b0:21d:aa7e:b1bb with SMTP id u10-20020a5d434a000000b0021daa7eb1bbmr21460245wrr.619.1660230629028; Thu, 11 Aug 2022 08:10:29 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id m27-20020a05600c3b1b00b003a308e9a192sm7198895wms.30.2022.08.11.08.10.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Aug 2022 08:10:28 -0700 (PDT) Message-ID: Date: Thu, 11 Aug 2022 16:10:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-GB To: internals@lists.php.net References: <62f48769.250a0220.37387.53b5SMTPIN_ADDED_MISSING@mx.google.com> <01D4987C-FD37-4BD2-A1AC-DD10F808F248@gmail.com> In-Reply-To: <01D4987C-FD37-4BD2-A1AC-DD10F808F248@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [Concept] Extension methods From: rowan.collins@gmail.com (Rowan Tommins) On 11/08/2022 10:03, Alex Wells wrote: > You could argue the problem is that all of these are single-liners, so here are the same examples, but multiline formatted: When people talk about avoiding one-liners, they're not just talking about whitespace, but other refactoring. For example, introducing intermediate variables: $fileNameComponents = explode('_', $file->getName() ); $slicedComponents = array_slice($fileNameComponents, 4); // (most likely there's a better variable name, which would explain *why* we're ignoring those components) $className = Str::studly( implode('_', $slicedComponents) ); Or adding additional helper functions: $fileNameComponents = explode('_', $file->getName() ); $slicedComponents = array_slice($fileNameComponents, 4); $className = Str::studlyFromArray( $slicedComponents ); Or even, since "Str::studly" probably calls explode() internally anyway: $className = Str::studlyWithSlice( $file->getName(), 4 ); >> On 11 Aug 2022, at 07:36, Paul Crovella wrote: >> >> An extension method would shift a single argument from inside parentheses to the left of the function name. It just moves it. I don't see any impact here. > > It doesn’t move it, it removes it. You’re technically not passing that value as an argument anymore anywhere in your code, your value becomes the implicit > expression you’re working with. That becomes even more obvious when multiple method calls are chained and don’t need to pass it into every function call. I think what Paul means is that "$foo->bar($baz)" and "bar($foo, $baz)" have the same "words" - the "$foo" is there in both cases, just in different positions. The same is true of nesting vs chaining: "$foo->bar()->baz()" has the same "words" as "baz( bar( $foo ) )",  just in a different order. I do agree that the left-to-right order is nicer to read than the nested version, but that's largely opinion - it's not actually any shorter. Regards, -- Rowan Tommins [IMSoP]