Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124110 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 4746B1A009E for ; Sun, 30 Jun 2024 15:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719762299; bh=IfEKrYrT4J3hpHPGHHcQjX9y9gG+Ts74uD6oQu2/xbg=; h=In-Reply-To:References:Date:From:To:Subject:From; b=aJN08NDdsEJp9lovvkhlaFQMX5fuK0OJJIcXmNAgI6zFUbKan8RNiOqyFMA8IzBK4 Cj8hghoApbVIgvcaSldo68d1fXuUXl3XcXSFujGjjz6IT+lhH5NyiC8lOzKEsD9XI9 Lp3p6mIAwl8nfq8GV2bDOfcuxm9k7EMvRbYNmwQF+1tdLBTeTnE6HuoJzBACoh2tBW JbWMZnrq+h7R+EZKleFYIcMwnZBFcPZoIE5IX3k+dGya+3J1amCL0yS4LJv6pUdtlS vQ3JjIldy+bqSRpZb67obJpW8JQbSyUwfX87XIiOgiWXaW9k8affvpezVQkELPwhWP Cc6W4EhHYGW4A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A37AE181BF2 for ; Sun, 30 Jun 2024 15:44:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 30 Jun 2024 15:44:53 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 7D08E180007F for ; Sun, 30 Jun 2024 11:43:31 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Sun, 30 Jun 2024 11:43:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1719762211; x=1719848611; bh=rwCK8HwZZ15AlM6gR++JW xkowgBur422Gev8UiB8Jkw=; b=olUdFj1aKVi6nHfSglT0DZrxpMG1UATOvsR/M vdimI4xd8UtRrwdK9cCfuP9yTP6uFvTfjAyticjy1gGOcZ3RqNmCp4N1g7kZdOBr Zb7/Ava7kTrQq4A/6vgKW/AXC3qzjJoQI3/1uit7yyVU0CImwBcDtnKit0UYbXAs fMqW11w4NXr7DVen2oJLDXX5JxFqF4JA51WihfOg38gUmO6D9dTgB5CoxpGSV892 OespzW14lWkRgqvrlrUyZ6mT9VbA/7R/oh2mKrO/gBzZYwQXrF9IHyY8IJ4jpzO7 Q59J3cjB8fSXg4GLtWhKAj82qw3TxHXAZjxoSWGCWs76XbloQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1719762211; x= 1719848611; bh=rwCK8HwZZ15AlM6gR++JWxkowgBur422Gev8UiB8Jkw=; b=v BM1oNtjGK20lqvqiY7leJGIs1xBfgmQc7sM6prdYcPY5QNJPNCNFZpVJUTPukS5T M+5KeOyk76Obp/RRWmzQNHRfg4AsNxCGXDSP+KvXF+BvScTN0CV0ce5HHNTLTn7V 9O28YykXF1f7OQhKzxA+VZ1sYi5VwKWnzNJ1Lvd83Fsh4nhMjtNNh7jhxuZPOn3s 7ItxwIEm4ttZM06dy6lTScW0gQThU20ySqRfLklD3jOnuBongRDb/6YdKu3Y+4B8 Uo1RLcatEJ5x/PpaJL8pRl/AEudJNj0KDZr39TOJm1I8OzOvlhpTdH49d2wbW18Y xlcE5RTUyxVtXdfuO/+nw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddugdelfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeffjeel feejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id D12C41700093; Sun, 30 Jun 2024 11:43:30 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <7f1ba41b-ace8-4af2-8efc-1412c47e34cb@app.fastmail.com> In-Reply-To: <3B23E039-D90F-4F84-9ECE-C6A9A3E145AF@sakiot.com> References: <668168A7.4040005@adviesenzo.nl> <3B23E039-D90F-4F84-9ECE-C6A9A3E145AF@sakiot.com> Date: Sun, 30 Jun 2024 10:43:01 -0500 To: "php internals" Subject: Re: [PHP-DEV] [RFC] [Discussion] Add bcdivmod to BCMath Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sun, Jun 30, 2024, at 10:11 AM, Saki Takamachi wrote: > Hi, > >>> Just a suggestion: what about making the returned array an associati= ve >>> array ? Like so: >>> ``` >>> array( >>> 'quotient' =3D> 61, >>> 'remainder' =3D> 1, >>> ); >>> ``` >>> This would remove the need for devs to remember the order of the ret= urn >>> values and would make the return value self-documenting. >>=20 >> An associative array would combine the worst of an array (no IDE auto= completion, no strong typing, increased memory usage) with the worst of = an object (no easy way to extract the values into local variables with a= rray destructuring). >>=20 >> The example in the RFC doesn't show it, but the following makes the p= roposed API really convenient to use: >>=20 >> $slicesOfPizza =3D new BcMath\Number(8); >> $mouthsToFeed =3D new BcMath\Number(3); >> [$perMouth, $slicesLeft] =3D $slicesOfPizza->divmod($mouthsToFeed); >>=20 >> Note how the order of values matches the words in the method name. Fi= rst the result of 'div', then the result of 'mod=E2=80=99. > > > Thanks, I have added this example to the RFC (Please let me know if yo= u=20 > have any problems). > > >> I came here to say the same thing. The best solution would be not hav= ing to refer to documentation or experiment with values, and this hits t= he nail on the head. >>=20 >> The only thing that makes it weird is having to write it out, which a= t that point, it is probably faster to type out bcdiv and bcmod separate= ly. >>=20 >> Have you considered simply using references passed to the function? I= feel like that is more idiomatically php. > > Of course, that idea was proposed, but it was pointed out that current=20 > PHP tends to avoid such implementations, so we didn't adopt it. The=20 > reason why passing by reference was not adopted was added to the RFC. > > Regards, > > Saki I agree an associative array is the second-worst option. An inout by-re= f argument is the absolute worst. Normally my default position is that when in doubt, make it a structured= object with properly defined properties, and screw whatever micro-perfo= rmance hit it is, you won't notice. 99% of the time I believe that is t= he correct approach. I can see the argument that this is the other 1%, since it's just two va= lues, which will basically always be wanted separately but both wanted (= meaning divmod(...)->divsor is kinda pointless), and their order should = be fairly self-evident. However, in that case I would urge that both the RFC and the resulting d= ocumentation *always* use examples that return into a `[$foo, $bar]` des= tructured list. Don't even suggest that people should use 0 and 1 index= es. It's a tuple for deconstruction, that's it, if you're using it some= other way you're probably wrong. Politely ignore that it's even possib= le, lest we lead people down the dark path. (Which means removing the current index-using example and just keeping t= he pizza example.) --Larry Garfield =20