Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112100 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3412 invoked from network); 22 Oct 2020 05:48:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Oct 2020 05:48:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 586C5180502 for ; Wed, 21 Oct 2020 22:05:56 -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,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 21 Oct 2020 22:05:55 -0700 (PDT) Received: by mail-qk1-f181.google.com with SMTP id k9so405546qki.6 for ; Wed, 21 Oct 2020 22:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=r66VcGG6XHIjo8Ytk6ukTwGfYD0513xnoV0hWxWWt4w=; b=dwKC7+2gYyPecJrI/OSLTTG5CymJfgnuIH5NPeUbvzOWWaR0l9mwEArG3hMA9ALxR4 DbAdZpPBdW1zD6CACroekDnxkkFY71utB9OiTIs7OWRR11QeBfyUrarfbReMigpC+ozR n9s0A0VhDjuYKDxkzshopLYbHlolp2jUV2raGSqAIv9evb7DtTBo8EoZjalmTfm9IRuE tX1shAtfszXBloDC+MpCg390HPIjMRp2SvxTT2j7BJNwU73QSVxoP+xOnx+C9UIbXFkC nuw/t/8E0hdP/JAYZok5PFHLuXSrZDYDbnuEzGRrXjgLy6Fk9KLf/9fM8ftc90sqw8oG xm2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=r66VcGG6XHIjo8Ytk6ukTwGfYD0513xnoV0hWxWWt4w=; b=GqNVKQT3NAAEmNbZXn4lfqydQ3LEYqCR/nibqigLJBPLGoWtqEEFvsE9IEnB1QMSME JKfRpqVnjtTRTtnkqAfvvfeYx614lXsSvtqNTV3uaOYaDRKqM9upr0VFZQQ7ynDY5suM 1I7ilAw0gI8JMwo+ddtjJguHenCx1vGdYfBi/BFCbI8wrz9rtb9vtjvsR4XSHsbNwtFS SIWsUSYRGfB48LplqKE0h/8KPMV1YEU4U/0BIrDdUU/4dSlN9HnvJ14URWYngs93d7Fp 5enWasxH/YF8X8EvYnYFRhv3r/2cxJRNMilrSYPW2ZDxJILVAGGUcaoXSnyPc4CMhW4o KdEw== X-Gm-Message-State: AOAM532223xBQA+E4c2XbShxzVnuLgRXrKuA9fuK+QrGXjj5M5EzuxhS JwC8CWjcjFAp/ZX9SI+Oa/Jweg== X-Google-Smtp-Source: ABdhPJytaTeyAwllACaJO27F2aojxVVzWqFgkyBMZ5SbhjEhe3H6zeCJ121MwYIIzoC0yI8DUK8imQ== X-Received: by 2002:a05:620a:21da:: with SMTP id h26mr760130qka.123.1603343151428; Wed, 21 Oct 2020 22:05:51 -0700 (PDT) Received: from [192.168.1.254] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id 22sm428862qkg.15.2020.10.21.22.05.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Oct 2020 22:05:50 -0700 (PDT) Message-ID: <509731F7-85F1-4845-8425-7238BD998250@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_E19B3952-F8A1-4E16-836E-7AB79D544A71" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Thu, 22 Oct 2020 01:05:49 -0400 In-Reply-To: <11124061-cfeb-4668-8a8d-a11aa683477a@www.fastmail.com> Cc: php internals To: Larry Garfield References: <41AA7084-18F3-431B-B135-46C44FC26D1E@newclarity.net> <11124061-cfeb-4668-8a8d-a11aa683477a@www.fastmail.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Short-function syntax From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_E19B3952-F8A1-4E16-836E-7AB79D544A71 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Oct 21, 2020, at 8:50 AM, Larry Garfield = wrote: >=20 > On Tue, Oct 20, 2020, at 11:08 PM, Mike Schinkel wrote: >>> On Oct 20, 2020, at 2:19 PM, Larry Garfield = wrote: >>>=20 >>> A while back, Nikita mentioned that it should now be easy to offer = an abbreviated syntax for functions that are just a single expression. = I decided to take a crack at it and it turns out he was right. I thus = offer this RFC: >>>=20 >>> https://wiki.php.net/rfc/short-functions >>>=20 >>> Hopefully I made a decent enough case for it. It's entirely a = convenience factor, but I think for many OOP cases (getter methods and = factored out operations) and functional cases (where functions should = generally be a single expression conceptually) it does make the code = nicer, more compact, and more readable. >>=20 >> Simple and elegant. I like it. >>=20 >> I have two comments, but not about the feature. =20 >>=20 >> One comment is about the RFC itself, and the other is about a = use-case=20 >> used to justify the feature that could warrant its own bespoke = feature. >>=20 >>=20 >> 1. The section on "Conditional methods" is really just an argument=20 >> about the benefits of encapsulating complex logic into well-named=20 >> functions as you could achieve exactly the same benefit with the=20 >> existing function syntax. It does not appear to me that it provides=20= >> any specific justification for the feature in the RFC. Should it = really=20 >> be part of the RFC? >=20 > In pre-RFC discussion, one of the pushbacks I got was "pfft, how = common are single-line methods anyway?" That example is mainly to = demonstrate "quite common, actually, in fact common refactoring patterns = tend to produce them a lot." It's not the refactoring itself that = benefits, per se, as it is the refactoring technique produces functions = that would benefit from it. Thank you for clarifying. I understand now why you included that = section. I think the problem I had understanding the section's purpose was the = construction of the first sentence where "common refactoring technique" = was its subject. =20 May I propose you consider a different construction that focuses on the = frequency with which single-expression functions are needed? Here is but = one such potential alternate: ----- "One might ask how commonly we need single-expression functions? = Consider the "if," "switch" and "while" statements. When their = expressions are complex, we can add clarity by encapsulating into a = single-expression function:" ----- Also it might be good to rename the section "Conditional methods" to = something like "Use-case frequency" to focus on the reason for = inclusion, or if the purpose of the heading needs to be about how it = would be used in the language then maybe "Control Flow Statement = Expressions" would be more appropriate? Anyway, just offering these suggestion in hopes that ensuring your RFC = is as clear as it can be will make it more likely to pass. -Mike >=20 >> 2. In the section "Decorating functions in live code" where you state=20= >> "Often times, methods exist that are just delegating to some other=20 >> method, either in the same object or a composed object." I think we=20= >> could see great benefit from explicitly building delegation into=20 >> classes much like how Go provides type embedding[1]. For PHP, = extending=20 >> the syntax for traits could be used to support delegation of one = class=20 >> to another embedded class. Can you see this as a potential feature? >>=20 >> -Mike >=20 > I'd be in favor of some kind of automated "delegate this interface's = methods to this object property" syntax, although that is unrelated to = the RFC at hand. >=20 > --Larry Garfield --Apple-Mail=_E19B3952-F8A1-4E16-836E-7AB79D544A71--