Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118415 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63994 invoked from network); 11 Aug 2022 13:29:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Aug 2022 13:29:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0CC201804B5 for ; Thu, 11 Aug 2022 08:31:53 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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:31:52 -0700 (PDT) Received: by mail-wr1-f43.google.com with SMTP id z12so21746711wrs.9 for ; Thu, 11 Aug 2022 08:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc; bh=OR31hgwD8sspDFmX+izqVTwfRE5m1um32pgPZPoRY6A=; b=lPwaDWpvTmCxCYv/lUSb7T9B/QZyCuaIBF1f53ZO1N+kamPCSIgQZ9c2gwmDkLhYUe f3RFYrjMQBl4+Mi1l5Fum6+ho5keMvMA6a+FW/+tZJ4tbWcGLkeHvsiKnzf2mzdzT6Te guBTbJQgSuF8B3Oif0/umwTGGGsekRE0606tR+D4gU3ceuWkXVzRcd8BmkG1vj0aouPL lff6IrtKmT+SVdWClb0dwetxW9O0td4j3XsP88TgQAvNELoc+QlEnxw/uLiIwqMNl/18 F5ZBFr7QzCDMcKRWN23bAzgG/1YQ+U0GBGNiAnPghLPofO1Do8TtrJGkHaohMe3ERph3 KoCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc; bh=OR31hgwD8sspDFmX+izqVTwfRE5m1um32pgPZPoRY6A=; b=AZkTNLXgzmw5spiU6EpEVnHmYohjT+zB3JeDAy5qLc9Dsv+7uJQ0nFtGJmTT8uTZ53 MiyKbtZEoK6MXt7KZ4zSBXwhc3Eb2iDyX+VWnIc4Hc0WWUjRe+tyUPI7akLzO2285Yfq myQ9EvYxdU1sKD3k2BjlyDAP8pQBy6gv4PTpdxTdQUIxdDrglYcC0RS752fWsHJScs4X aCwYy0midxPe2hw4osjZJbyD8dCDBveMqZWLTEjXmrS1A0CbB1swjdj8iPd5xW97L+Bd 3D2tIGodFT+dUrvVRr3SUg+0eB5GQc0Fy+pUB0y7XahALedAEGkELz2Qsh/abzLVl3Yu 0BUA== X-Gm-Message-State: ACgBeo0jbIu6Rx20RZWkN5KAi29DtYpPy+43rcYJNUu7StLeUXVtyKJU iKYLNRWlY316yu1SO5fD9xshjGG0ZOCCgg== X-Google-Smtp-Source: AA6agR7Gg5DEE2E1iY3MzwDO3iUz0aiSkJwaQdEBOi9RB+NBrgqEXjHyBJPOGrnRPuHUXCJd/wUGgA== X-Received: by 2002:a5d:64eb:0:b0:220:6bf8:70b6 with SMTP id g11-20020a5d64eb000000b002206bf870b6mr20180969wri.235.1660231911357; Thu, 11 Aug 2022 08:31:51 -0700 (PDT) Received: from smtpclient.apple ([213.109.238.56]) by smtp.gmail.com with ESMTPSA id i12-20020a1c540c000000b00397402ae674sm6369257wmb.11.2022.08.11.08.31.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2022 08:31:50 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) In-Reply-To: Date: Thu, 11 Aug 2022 18:31:48 +0300 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <0EEBD1D1-3F49-403C-86AB-8BE456C374A8@gmail.com> References: <62f48769.250a0220.37387.53b5SMTPIN_ADDED_MISSING@mx.google.com> <01D4987C-FD37-4BD2-A1AC-DD10F808F248@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3696.100.31) Subject: Re: [PHP-DEV] [Concept] Extension methods From: autaut03@gmail.com (Alex Wells) > On 11 Aug 2022, at 18:10, Rowan Tommins = wrote: >=20 > 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: >=20 >=20 > When people talk about avoiding one-liners, they're not just talking = about whitespace, but other refactoring. For example, introducing = intermediate variables: >=20 > $fileNameComponents =3D explode('_', $file->getName() ); > $slicedComponents =3D array_slice($fileNameComponents, 4); > // (most likely there's a better variable name, which would explain = *why* we're ignoring those components) > $className =3D Str::studly( implode('_', $slicedComponents) ); >=20 > Or adding additional helper functions: >=20 > $fileNameComponents =3D explode('_', $file->getName() ); > $slicedComponents =3D array_slice($fileNameComponents, 4); > $className =3D Str::studlyFromArray( $slicedComponents ); >=20 > Or even, since "Str::studly" probably calls explode() internally = anyway: >=20 > $className =3D Str::studlyWithSlice( $file->getName(), 4 ); >=20 I agree that this is a solution for many cases. However, the goal of the = comparison was to show reduced cognitive complexity, which I don=E2=80=99t= believe is what was achieved by splitting a simple expression into = mulitple lines with multiple variables. It gets progressively harder to = =E2=80=9Cscan through=E2=80=9D if you=E2=80=99re just trying to get a = global picture of what=E2=80=99s happening and not specifically = understand why these lines exist and what they=E2=80=99re doing. = Sometimes you just need a neat one-liner and that=E2=80=99s enough :) Besides, variables are statements, making these a statement list, not an = expression, meaning they can=E2=80=99t be used as one in an arrow = function or a throw expression.=