Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110041 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91002 invoked from network); 6 May 2020 14:05:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 May 2020 14:05:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6487B1804E4 for ; Wed, 6 May 2020 05:40:49 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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, 6 May 2020 05:40:48 -0700 (PDT) Received: by mail-lj1-f170.google.com with SMTP id f11so2202162ljp.1 for ; Wed, 06 May 2020 05:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qj4JO9kams0kNDuQGx9OjAG/RvgTDDazu8QcTA4aGfI=; b=t5lfqYUqA9b8bGumsu/Z85MbyTXAT4o/fqb/gFRLcpCaOpyMqMXXjSw2tDXU6KyMP5 B9ZtWTizrnAFuqp4Teb79oCtj2HuvllbSAo1ECbG7MQGNmZwFdcIs+Sa3fhyY3/E0T/F J6/Oz0Qowu+ujbVah80lBdbYDzQsHzm7uDEhX0OIjRgU8RVuJ1mhhXFCoI4orOFD0dxX KbhLQVu/Bn3UCqCWcl+VvtsJRn7Jjr2zavEfnasuGWxqCJxQ6/LZQQKr7onuPIvMWVuK /FMAHZeN3O3ogWsfCVMlKW2P1/nmp7Mp5ZjHhaBtQ1YjLMCkRpKT7u61kMLbKzbbqA7U sBHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qj4JO9kams0kNDuQGx9OjAG/RvgTDDazu8QcTA4aGfI=; b=aituqQFL3sBMdb5oCVFufr9fT06eP+QeT4WoBdG2+1v7sFx/owNxGmmO8S1Y6jByMW a0P/1B7Elwb3Z57xO5MirbdJFXCiiD6Zijomk8SrdfrXamEvw9rVnlePvapjnwDPVa2y W3Mberx1T3wTTb7c+yFZx05pP7MoWQh+ECeU/tL8KbZlfJpRVBpCqrkkwBQ8gqYM5AHJ PZ0m2r0GaV1uCBFDl1WDnbgX5FYkhg5vT5zjbda0LsJzQPVskH87Dbd+C2RgwG5PrYEF RbZbCV/NzzuAzsmgrbdfebKX3Ybj0HIe225PpfPtDmZWMVhqwHX2FFEy9BHFAubjBr0O vNxw== X-Gm-Message-State: AGi0PuZS1sIZVkW9c7lznDDZZahn6xDaOWm68hqU6d1S67MIcQo43Erp h33jhjtE7vcSNCSGnFsJmB8VLxQup6FLRgvUV5g= X-Google-Smtp-Source: APiQypIu/wCWnPYks4msXklY79fvKdmDo4w8VQVqfeB+lFarofvjzTeeMEPK6oHrf0AkpyqInkJgEcU0xoXBGZlUt58= X-Received: by 2002:a2e:81d5:: with SMTP id s21mr4734837ljg.258.1588768845847; Wed, 06 May 2020 05:40:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 May 2020 14:40:28 +0200 Message-ID: To: Lynn Cc: Marco Pivetta , Theodore Brown , PHP internals Content-Type: multipart/alternative; boundary="000000000000afe16a05a4fa12b3" Subject: Re: [PHP-DEV] [RFC] Named arguments From: nikita.ppv@gmail.com (Nikita Popov) --000000000000afe16a05a4fa12b3 Content-Type: text/plain; charset="UTF-8" On Tue, May 5, 2020 at 8:38 PM Lynn wrote: > > > On Tue, May 5, 2020 at 8:22 PM Nikita Popov wrote: > >> Anyway. Your point that named arguments expand the API surface has been >> acknowledged. I don't think this issue is really avoidable, it's a rather >> fundamental trade-off of named parameters. I do think you're a bit quick >> in >> jumping to conclusions. It's not like this problem doesn't exist in >> (nearly) every language supporting named arguments. >> >> There are some things we can do to mitigate this though. One that we >> recently discussed in chat is to allow methods to change parameters during >> inheritance, and allow named arguments to refer to the parameter names of >> the parent method as well. Renaming parameters in a way that causes >> conflicts (same parameter name at different position) would cause an LSP >> error. I'm not entirely convinced this is the best approach yet, but this >> does address some concerns (including the "interface extraction" concern >> you mention on reddit). >> >> Another is to allow specifying the public parameter name and the private >> parameter variable name separately, as is possible in Swift. This would >> allow changing "parameter" names arbitrarily, without breaking the public >> API. This would be a pretty direct counter to your concern, but I'm not >> really sure that your concern is important enough to warrant the >> additional >> weight in language complexity. I've never used Swift myself, so maybe this >> is actually awesome and I just don't know it. >> >> Regards, >> Nikita >> > > Hi, > > If I understand this correctly, something like this could be done? > > ``` > // current version, argument name = "firstArgument" > function example(string $firstArgument) {} > // name changes, bc can be kept, argument name = "firstArgument" and > "argument" > function example(string firstArgument: $argument) {} > ``` > This would make it possible to keep backwards compatibility, and perhaps > even trigger a notice when called with the old name? > Yes, that's what I had in mind. However, after thinking about it a bit, I don't think adding such functionality is worthwhile in PHP. As Rowan explained in another mail, the named arguments functionality in Swift is quite distinct from named arguments in other languages. It is used in a way that makes it more common for external labels to differ from internal names. For the rare case where something like this would be useful in PHP, we already have function example(string $firstArgument) { $argument = $firstArgument; // ... } as an existing way to internally rename an argument. If we had reason to believe that this was commonly needed, then introducing special syntax for it might make sense. But I don't think think we have such evidence. We do have some evidence to the contrary in that Swift is the only mainstream language I'm aware of that has felt it necessary to introduce such a syntax (and as mentioned, Swift's "named parameters" are really more like "named functions where part of the name is inside the parameter list"). Regards, Nikita --000000000000afe16a05a4fa12b3--