Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110016 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95022 invoked from network); 5 May 2020 19:24:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2020 19:24:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 00FF118054A for ; Tue, 5 May 2020 10:59:50 -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-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (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 ; Tue, 5 May 2020 10:59:49 -0700 (PDT) Received: by mail-il1-f175.google.com with SMTP id t12so2585026ile.9 for ; Tue, 05 May 2020 10:59:49 -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; bh=aj6+7IDyBfvUKzybU2nbPRegpRfKgvYNoZS5FrQXOMM=; b=DHc0VQ5Nqed2Po8SFXvJRG7XtGhYiKuMoRUhjQWHlkhfOiATzfQg14yIl/unDvsJy1 3b4hvLxqUQbKKtKgAvUlPFlvazDga6TSTNwBwKJLow5BZ8yVTglO2DURHytKfZC0362e RObH+twg1zC+jkq+57465mhJfPN8OP4YpREBwFLXRtl5W8fjyHZQsQ+YNUlpss2eU+lZ pHIOWnd7FAg8AWLakwhZhC+RagMBV2v5RL+iOT5rc7VcuhpyB5edli28kZG59JWHkW6X QWzy4DOCbLXqAPwvSL2Gcyaq3tDBd4C6Jk3JkSl324dpmjRy+LBFn7p9Dn6xBLtsEuNL XFGw== 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; bh=aj6+7IDyBfvUKzybU2nbPRegpRfKgvYNoZS5FrQXOMM=; b=RL5ZWTKGKSVC9m9HUEg2RaHzPyPBW/g7gIxAH15l9lTsxmdJ4pPJPNVGAsJLmyQFtF HEVayFh7qrKxlHtmBj1JH0CxdavnSqa2yexIwPrnQAB00sCF3umgKkwC3aeVpzLXVsOp gp7lycT24SI310U9aNeMa5evlIF7ApricXnHm89Eym+NQlt7cbp9tCmjf0/97Kt9+pbZ xZxdyMRenRGwf/qufxi1t/9+GLzF/RaaTi8WBwU5p9/XgFOT4tNJnTOMzluFe6L1A6OQ kFG+h+n+Y7l+wLYT6qEjN0QmWPUKfHM56lYZvFhOYiwquQENuiNNTdv6X/m/9VCBtWy0 emlA== X-Gm-Message-State: AGi0PuY70yGqV2WfDe4bjiJ8wkgLmvzmG6PCeMH/8o7qgN8y4qd+EDaS 3OIR6ndlDr1aP55G5rI19FJ3QUkFlMD6U1QcT/gbA/RP X-Google-Smtp-Source: APiQypKcaZ3xzSHfObi6x9xOup7GV2MxAftx7wABUYyuVkQxnZptKwent4sGy2RZFvprvgaXxT1PfQ2Jq20wpc4uXk4= X-Received: by 2002:a05:6e02:dcf:: with SMTP id l15mr4977989ilj.225.1588701586265; Tue, 05 May 2020 10:59:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 5 May 2020 18:59:34 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000b41b8705a4ea696b" Subject: Re: [PHP-DEV] [RFC] Named arguments From: rowan.collins@gmail.com (Rowan Tommins) --000000000000b41b8705a4ea696b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 5 May 2020 at 18:19, Marco Pivetta wrote: > > I do in fact consider the `ParamNode` example in that API to be a bad > candidate for named parameters, since I'd make all of the arguments in th= at > signature required anyway: defaults aren't meaningful anyway, as the AST > library where it comes from has all the context to instantiate them all > (the caller, being the parser, will have all the parameters anyway). > Parameters don't need to be optional to benefit from named syntax; they just need to be hard to parse by a human writing (and reading!) the call. An obvious example is PHP's needle/haystack inconsistencies that everyone loves to hate. If all parameters were named, strpos(haystack: $content, needle: 'hello') would be fine and I wouldn't have to look up in the manual to check I had them in the right order. An interesting example is network protocols originating from contexts where parameters are named. Take AMQP, the messaging protocol used by RabbitMQ. In PHP, you would currently write something like this to declare a queue in no-wait mode: $channel->queue_declare('hello', false, true, false, false, true); In Python (or Ruby, or C#, or Elixir, or...) you can make it much more readable *even when providing all the arguments*, and don't have to remember what order things go in: channel.queue_declare(queue=3D'hello', durable=3DTrue, nowait=3DTrue, passive=3DFalse, exclusive=3DFalse, auto_delete=3DFalse) Those aren't arbitrary names chosen by the Python client, either; they're listed in the protocol spec: https://www.rabbitmq.com/amqp-0-9-1-quickref.html#queue.declare queue.declare(short reserved-1, queue-name queue, bit passive, bit durable, bit exclusive, bit auto-delete, no-wait no-wait, table arguments) =E2=9E=94 declare-ok Incidentally, this leads to the one part of John Bafford's counter-proposal I would be fundamentally opposed to: > Parameters are also positional. foo(a:..., b: ...) and foo(b: ..., a: ...) are two completely different functions, by name. If you have foo(a:b:) defined, then you cannot call it as foo(b: ..., a: ...). Re-ordering is, IMO, a key advantage of named parameters, so banning it feels both arbitrary and counter-productive. Regards, --=20 Rowan Tommins [IMSoP] --000000000000b41b8705a4ea696b--