Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122657 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 B6FAD1AD8F6 for ; Sat, 16 Mar 2024 14:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1710599927; bh=nUj9+YDFiCxAhJbSdoKu++oNXUWXs9n23RErWMXjsis=; h=Date:Subject:To:References:From:In-Reply-To:From; b=AZbwqbqrm5kJzCI3N1KC/0SmP6WoczPvRt7B3ZoKqxOk11s/Y44urprFFQCMEkgt+ f6m5K9GkkVtrW6h6tLqfsTH2OG4w0XT0Kz2LVO0z2sF2asOz/Ua+BY7T0uRhW6DGRG cCU7YMhwNBISjhhKnskTy1MTnfVRvsEGQtSRpn2A3arLdxMixydf3VOV1y1Zz3fNTZ ZXlw79O79vmZWMjfjM3XM7sdvGdKxRZBzfYVUGoduyfUtngORpqH1CSuTyqfzRrx8v EYyDqHfwfntpx2+owkkByKA2/v346AQu0Er1JN45GVrnGbHLXqER6cRdKZ/+M8tDPy 525fwDFgwKmIQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CA880180077 for ; Sat, 16 Mar 2024 14:38:46 +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=1.0 required=5.0 tests=BAYES_50,DMARC_MISSING, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from gliadin.co.uk (gliadin.co.uk [80.82.115.221]) by php-smtp4.php.net (Postfix) with ESMTP for ; Sat, 16 Mar 2024 14:38:46 +0000 (UTC) Received: from [192.168.0.17] (hari-18-b2-v4wan-169870-cust740.vm1.cable.virginm.net [92.239.242.229]) by gliadin.co.uk (Postfix) with ESMTPSA id 924A3FA29C2 for ; Sat, 16 Mar 2024 17:38:26 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------6EubWVxdfO7tX0qAg78IL9Xr" Message-ID: Date: Sat, 16 Mar 2024 14:38:24 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Supporting object types in BCMath To: internals@lists.php.net References: <6253DBFE-CF26-4189-AB9A-8233E411276F@sakiot.com> Content-Language: en-US In-Reply-To: <6253DBFE-CF26-4189-AB9A-8233E411276F@sakiot.com> From: barney@redmagic.org.uk (Barney Laurance) This is a multi-part message in MIME format. --------------6EubWVxdfO7tX0qAg78IL9Xr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 16/03/2024 05:22, Saki Takamachi wrote: > Yet another idea is to also support immutable objects, like DateTime. > > e.g. > ``` > $num1 = new BcNum('1.235'); > $num1imm = new BcNumImmutable('1.235'); > $num2 = new BcNum('2.001'); > > $num1result = $num1->add($num2); > $num1immResult = $num1imm->add($num2); I would suggest if you do this only supporting immutable objects, or at least making immutable the default, the one with with the simpler name, and reserving the mutable version specifically for when people want to use mutability. The strings used with bcmath today are effectively immutable. It's hard to see why a number should be mutable though. Users of the class can always wrap an immutable up it in a mutable object if they want. If you do have both mutable and immutable it might be worth giving the methods separate names to make the distinction clearer - e.g. "add" for mutable, "plus" for immutable, and maybe making the add method return void. --------------6EubWVxdfO7tX0qAg78IL9Xr Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 16/03/2024 05:22, Saki Takamachi wrote:
Yet another idea is to also support immutable objects, like DateTime.

e.g.
```
$num1 = new BcNum('1.235');
$num1imm = new BcNumImmutable('1.235');
$num2 = new BcNum('2.001');

$num1result = $num1->add($num2);
$num1immResult = $num1imm->add($num2);
I would suggest if you do this only supporting immutable objects, or at least making immutable the default, the one with with the simpler name, and reserving the mutable version specifically for when people want to use mutability. The strings used with bcmath today are effectively immutable.

It's hard to see why a number should be mutable though. Users of the class can always wrap an immutable up it in a mutable object if they want.

If you do have both mutable and immutable it might be worth giving the methods separate names to make the distinction clearer - e.g. "add" for mutable, "plus" for immutable, and maybe making the add method return void. --------------6EubWVxdfO7tX0qAg78IL9Xr--