develooper Front page | perl.perl5.porters | Postings from August 2021

Re: Pre-RFC decimal data type

Thread Previous | Thread Next
From:
Darren Duncan
Date:
August 6, 2021 00:09
Subject:
Re: Pre-RFC decimal data type
Message ID:
0c75d59d-3b96-fbe7-e34f-f69346ba2486@darrenduncan.net
On 2021-08-05 5:03 p.m., Darren Duncan wrote:
> On 2021-08-05 9:53 a.m., Harald Jörg wrote:
>> To add to the Java misery: If you retrieve a Java BigDecimal, e.g. from
>> a database, and want to add one, you need to create a new object:
>> value = value.add(new BigDecimal(1)).  Compare that to Perl's $value++.
> 
> I would consider creating a new object to be a feature rather than a misery. 
> Numbers should be immutable. -- Darren Duncan

Also your $value++ example isn't the same thing, it isn't mutating the object, 
its assigning a new thing to $value.

If someone had this:

   $v1 = 42;
   $v2 = $v1;
   $v1++;

Then $v2 would still point to 42.

I would expect/desire even with bignum libraries, that adding one to $v1 would 
NOT change the value in $v2, same as with small numbers, but if the number 
object is mutable then it would.

-- Darren Duncan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About