Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110006 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97459 invoked from network); 5 May 2020 16:54:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2020 16:54:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 408C11804C3 for ; Tue, 5 May 2020 08:29:14 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 5 May 2020 08:29:13 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 8D0EC831 for ; Tue, 5 May 2020 11:29:12 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Tue, 05 May 2020 11:29:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=43RJ65 5s1DvNFm0kz1DKy/GBl/RROZiAVFVxjo0d1hY=; b=ESYl0h3y8ty+vrAaPidlTM dgUSmHcNodr4nr4bHilMlbS6akbbM7zPbTM+7uJMMQPp21uLoeQh2V8QfzcSwIoo 774FeT7pJyEFkXok14Y2yJJry0yrGvhKbi3FDZ59hTIsLbttKPXoVXCXg6/ToHqK OSUlA7pZKRLdwroCs46V88xAkGQxVBJDBbd+yroWYNNlzXEzMTCD+rBH62exMzHr CfLUXWK7DzV7dY0p+hI96mKVx56asrdEmTYxxcicbYNfCDJhgzQ4lWCqd48TOxw0 VlfJ+Tu9zozvYCBWxUKQoKZgfmM2TAIGcTfV145NrewMH214tCI/+R0GZI7wpTfg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrjeeigdekhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnheptdfhffeufffgledttdfhueejteelgeejgfejfeevjeff tdfftefhtddvueffgeeknecuffhomhgrihhnpegvgihtvghrnhgrlhhsrdhiohdpphhhph drnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id C51F214200A2; Tue, 5 May 2020 11:29:11 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-dev0-351-g9981f4f-fmstable-20200421v1 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Tue, 05 May 2020 10:28:51 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Named arguments From: larry@garfieldtech.com ("Larry Garfield") On Tue, May 5, 2020, at 9:11 AM, Marco Pivetta wrote: > Hey Nikita, > > On Tue, May 5, 2020 at 3:51 PM Nikita Popov wrote: > > > Hi internals, > > > > I've recently started a thread on resurrecting the named arguments proposal > > (https://externals.io/message/109549), as this has come up tangentially in > > some recent discussions around attributes and around object ergonomics. > > > > I've now updated the old proposal on this topic, and moved it back under > > discussion: https://wiki.php.net/rfc/named_params > > > > Relative to the last time I've proposed this around PHP 5.6 times, I think > > we're technically in a much better spot now when it comes to the support > > for internal functions, thanks to the stubs work. > > > > I think the recent acceptance of the attributes proposal also makes this a > > good time to bring it up again, as phpdoc annotations have historically had > > support for named arguments, and this will make migration to the > > language-provided attributes smoother. > > > > As mentioned some days ago, I see named parameters as an added liability, > rather than values. > The rationale of my negativity around the topic being that a diff like > following is now to be considered a BC break: > > ```diff > -function foo($parameterName) { /* ... */ } > +function foo($newParameterName) { /* ... */ } > ``` > > In addition to that, the feature seems to be especially designed to work > with particularly bad API (anything with a gazillion optional parameters, > such as all the OpenSSL nightmares in php-src). > In practice, the issues around bad API (in this case, bad = lots of > optional parameters, maybe even ordered arbitrarily) are fixed by using > proper value types and structs or value objects: > > ```php > myHorribleLegacyAndOrganicallyGrownApi( > > ...MyInfiniteSequenceOfParametersAsProperValidatedStructure::fromArray($stuff) > ->toSequentialParameters() > ); > ``` > > For the few use-cases where this is needed, the userland solution seems to > be sufficient, without introducing catastrophic BC boundary expansions. > > Unless I'm not seeing an incredible (hidden, to me) value from this > functionality, this is a clear -1 from me. I agree that named params can be used as a crutch for poor API design. However, that's not always the case. The biggest use case I see is, as discussed previously, value object constructors. "Pass an entirely untyped and undocumentable array of parameters" is not an sufficient userland solution in my mind, but is the only available alternative right now. Attributes, now that those are a thing, are another very good use case, IMO. The combination of constructor promotion and named params gives us an effective equivalent to structs and struct-creation from Go or Rust or similar languages with a minimum of overhead, allowing for typed, lintable, efficient data structure definitions to more easily replace "big anonymous associative arrays." Those are way worse than the API abuse named parameters could offer. I share your concern that it could get abused; so does anything else though, for that matter. Part of that could be addressed with good documentation and education. If we had to change the approach, then I would be open to limiting them to constructors as that's where the really big use cases are. I don't know if that inconsistency would be worse than allowing them everywhere, though. --Larry Garfield