Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124108 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 761E11A009C for ; Sun, 30 Jun 2024 15:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719761619; bh=UEDwssbMA1KOJ7olngVRT00QNRFGamR+F8ZmWC7Wjcg=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=BDzoxyBefPTxdmiIV2XTLuPd//bpQ2yD+peZYCzi3Rc/LW3rInldmhbvqcB9dk2k2 dZNqAOwaPYer/SE3mokrQqRTQ2dsF62CnpWNdYOFQUo8LwlKA26UjOYhv8kahugO4h t0uN7+wPU8u8zXWiwVzLvWO5cKC0fC9qabCOvZ/M1JLwz53c/accbpf2zHKpxMz8sM 7NS1c0maNdjhBoT9Yp9VQjE0L/VjiILdLNMPkQXOAoOyVXDQBu424rBqgzIdu6poec ofgHtEEVzn6CU6VuV639fJs1yp/7IbX3R4iEy7wgAPF5hku6RLr2M9sDFaSpW4ND2O Z3zpdC+U0RIRg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8631318187E for ; Sun, 30 Jun 2024 15:33:38 +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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, 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 fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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:33:37 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 96EC9138017E; Sun, 30 Jun 2024 11:32:17 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Sun, 30 Jun 2024 11:32:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc: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=fm3; t=1719761537; x= 1719847937; bh=k72waW/7ZzxD4yizXEkzKnOxvjz0qOcdWO857X3NYRg=; b=r W6/SUC/XreQEf7NhpHjVSumr20kmbgPJnpm5uRnJdam9HJkhckC4OBnDiYdMHxsj yvywPNOpkDsUaoxX+FjTNgteEScZQfn3/HnVvIMdThEevHoBZAfb51knoA+QW2HS uwusYba+iPHROVaqlOxyxpzJlfn1qc/aUJBePMvkH7/mJFy/CefVQK3+Hc9GfBxp LOTcGls297jEz1tfBSxsX/WcTbx46kSy/TYcSahae+gsvqnTVQ+hV2cbPKJEwCI6 BRrQf/uhoMoAbh8vICdIoIMXQF9SUaRT613WQBGP0a+WXCjDFEwsTKLXCmtNQCSx 1h3t0ASM1gRRbaPJhEsNg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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=1719761537; x=1719847937; bh=k72waW/7ZzxD4yizXEkzKnOxvjz0 qOcdWO857X3NYRg=; b=q0ahS4Ht+POHBFCaUXiRIo2E4fDzTIIPInhMv9M0teXJ /HvjmuoGRz+z9+IoTjwRZSDA7Zl2+maU4SQryzWmq+eSUKMTdLufU/Vn5zX4qhx1 hioaFKvOvozT6caYd9ZzArSFFqSylbaVXd/dVTRGJc4XNfaonSiJbVo8ZOREfT7T /RL5pGwEqpybzPM/UQxL7vk5N+otN4Qb0mTizX91nJwVz61sTL195+oFykjTs46E JMIorpht3eOJ/p0rWdrAhSMxqvHSETDjWPhbCVOaTaEwm/BykIbUr3VYlQyigT9G 3KFnklfZybOLgYFNyxK6R6wBqPgXLTS+8wyu3GIbNA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddugdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesrgdtreerreerjeenucfhrhhomhepfdftohgs ucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrg htthgvrhhnpedvheekteelveetfeevgeekgfffvdeuhfelveehvdetiefggedtfeejheet gffhueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5A12315A0092; Sun, 30 Jun 2024 11:32:17 -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: <870bb837-400c-4a86-ab49-2ffef9d80ce7@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 17:31:57 +0200 To: "Saki Takamachi" Cc: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] [Discussion] Add bcdivmod to BCMath Content-Type: multipart/alternative; boundary=2d5a8ea9d3c84a87a7380d52226e561c From: rob@bottled.codes ("Rob Landers") --2d5a8ea9d3c84a87a7380d52226e561c Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Jun 30, 2024, at 17:11, Saki Takamachi wrote: > Hi, >=20 > >> Just a suggestion: what about making the returned array an associat= ive > >> array ? Like so: > >> ``` > >> array( > >> 'quotient' =3D> 61, > >> 'remainder' =3D> 1, > >> ); > >> ``` > >> This would remove the need for devs to remember the order of the re= turn > >> values and would make the return value self-documenting. > >=20 > > An associative array would combine the worst of an array (no IDE aut= ocompletion, no strong typing, increased memory usage) with the worst of= an object (no easy way to extract the values into local variables with = array destructuring). > >=20 > > The example in the RFC doesn't show it, but the following makes the = proposed 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. F= irst the result of 'div', then the result of 'mod=E2=80=99. >=20 >=20 > Thanks, I have added this example to the RFC (Please let me know if yo= u have any problems). >=20 >=20 > > I came here to say the same thing. The best solution would be not ha= ving to refer to documentation or experiment with values, and this hits = the nail on the head. > >=20 > > The only thing that makes it weird is having to write it out, which = at that point, it is probably faster to type out bcdiv and bcmod separat= ely. > >=20 > > Have you considered simply using references passed to the function? = I feel like that is more idiomatically php. >=20 > Of course, that idea was proposed, but it was pointed out that current= PHP tends to avoid such implementations, so we didn't adopt it. The rea= son why passing by reference was not adopted was added to the RFC. >=20 > Regards, >=20 > Saki I guess it could go either way: returns by structured array examples: - getimagesize() - parse_url() - pathinfo() - stat() - posix_getpwuid() and then these by reference: - list() -- kinda - array_shift(), array_pop(), etc. - preg_match*() - all the sorts Just thinking through it, return by reference is much more common in PHP= than returning structured arrays, and the ones that do make a ton of se= nse that they do (lots of data). =E2=80=94 Rob --2d5a8ea9d3c84a87a7380d52226e561c Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Sun, Jun 30, 2024, at 17:11, Saki Takamachi wrote:
=
Hi,
<= div>
>> Just a suggestion: what about making the ret= urned array an associative
>> array ? Like so:
>> ```
>> array(
>&g= t;      'quotient' =3D> 61,
&g= t;>      'remainder' =3D> 1,
>> );
>> ```
>> This wou= ld remove the need for devs to remember the order of the return
>> values and would make the return value self-documenting.<= br>

> An associative array would c= ombine the worst of an array (no IDE autocompletion, no strong typing, i= ncreased memory usage) with the worst of an object (no easy way to extra= ct the values into local variables with array destructuring).
<= div>> 
> The example in the RFC doesn't show it= , but the following makes the proposed API really convenient to use:
=

>    $slicesOfPizz= a =3D new BcMath\Number(8);
>    $mouths= ToFeed =3D new BcMath\Number(3);
>    [$= perMouth, $slicesLeft] =3D $slicesOfPizza->divmod($mouthsToFeed);
=

> Note how the order of values ma= tches the words in the method name. First the result of 'div', then the = result of 'mod=E2=80=99.


Tha= nks, I have added this example to the RFC (Please let me know if you hav= e any problems).


> I came= here to say the same thing. The best solution would be not having to re= fer to documentation or experiment with values, and this hits the nail o= n the head.

> The only thing t= hat makes it weird is having to write it out, which at that point, it is= probably faster to type out bcdiv and bcmod separately.
&= gt; 
> 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 PHP tends to avoid such implementations, so we = didn't adopt it. The reason why passing by reference was not adopted was= added to the RFC.

Regards,
<= br>
Saki

I guess it = could go either way:

returns by structured = array examples:

- getimagesize()
<= div>- parse_url()
- pathinfo()
- stat()
<= /div>
- posix_getpwuid()

and then = these by reference:

- list() -- kinda
- array_shift(), array_pop(), etc.
- preg_match*(= )
- all the sorts

Just thinki= ng through it, return by reference is much more common in PHP than retur= ning structured arrays, and the ones that do make a ton of sense that th= ey do (lots of data).

=E2=80= =94 Rob
--2d5a8ea9d3c84a87a7380d52226e561c--