Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110023 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42029 invoked from network); 5 May 2020 21:08:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2020 21:08:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC6051804E4 for ; Tue, 5 May 2020 12:43:27 -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.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS701 96.241.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (unknown [96.241.205.3]) (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 12:43:27 -0700 (PDT) Received: from [10.0.1.2] (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id 4F4A92005E81B; Tue, 5 May 2020 15:43:26 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 nebula.zort.net 4F4A92005E81B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zort.net; s=zort; t=1588707806; bh=xDlPZteBdJYNDicsJRzqDO4IDT/VldmE0h2XpVZWQoo=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=p08DQNqmgHQLjj9mmA7K0Rt6nOqBbNCwNju/7W7vAbS91AarefMFrJyFtDwUlx44c 24yRd0rqTOewmZpIFVKxpvlxe2mLb5sF6ILcneMFFAmqzYVGtsnW6PDXriaQLRSxkJ OGAw8GiBftc5000bWSdegAeH3p/xmcxCJYose4n4= Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) In-Reply-To: Date: Tue, 5 May 2020 15:43:26 -0400 Cc: Marco Pivetta , Theodore Brown , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <5C52A68A-482E-4F1E-A6C6-158A25D5901A@zort.net> References: To: Nikita Popov X-Mailer: Apple Mail (2.3608.80.23.2.2) Subject: Re: [PHP-DEV] [RFC] Named arguments From: jbafford@zort.net (John Bafford) On May 5, 2020, at 14:21, Nikita Popov wrote: >=20 > 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. >=20 > Regards, > Nikita The proposal in my earlier email is very much inspired from Swift. I = think having distinct outside and inside names helps greatly with = creating expressive and readable APIs. The most expressive name for a = thing might differ greatly between inside and outside contexts. Also, = the name of a parameter as used by the inside of a function should be an = implementation detail; there's no reason it should have to be exposed to = the outside. For example, Swift's Array has the following two methods (slightly = simplified): func firstIndex(of element: Element) -> Int? func firstIndex(where predicate: (Element) -> Bool) -> Int? You call them like: array.firstIndex(of: someElement) array.firstIndex(where: { $0 =3D=3D someElement }) =46rom the outside, firstIndex(of: ...) is more readable than = firstIndex(element: ...) because it reads more like natural language. = Same with firstIndex(where: ...) vs. firstIndex(predicate: ...). On the = inside, calling it "element" and "predicate" help you focus on what it = _is_, without worrying about calling it something that also retains = meaning to callers. If you at some point decided to have a mass-renaming of "predicate" to = "test", you could change that everywhere in your library without forcing = any sort of change to users, because predicate is "on the inside". And = both of them starting with 'firstIndex(' gives them a clear = relationship; they generally do the same thing, just with a type of = input. With php currently, you would probably implement those as: function firstIndexOfElement($element) function firstIndexWithPredicate($predicate) $collection->firstIndexOfElement($element); $collection->firstIndexWithPredicate($someCallable); But I think that's more wordy, and now you have either a BC break or = need to add a new function if you decided to rename all instances of = "predicate" to "test". A more readable API might look like this: $collection->firstIndex(of: $element); $collection->firstIndex(where: $someCallback); which is less typing, presuming your IDE didn't offer autocomplete for = you anyway. -John