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.