Method names for Valhalla value types

Chen Liang chen.l.liang at oracle.com
Wed Sep 10 16:31:39 UTC 2025


I agree an adjective or a noun method name to indicate a derived distinct object is better. Such pattern is seen in some wrapper class methods, like Integer.lowestOneBit. A verb name like "add" works better for static methods that take two BigDecimal. Since Brian is talking about type classes in this JVMLS, I would assume the verb names like "add" would be more suitable for the type classes than on the numeric types themselves.

Chen
________________________________
From: valhalla-dev <valhalla-dev-retn at openjdk.org> on behalf of Pedro Lamarão <pedro.lamarao at prodist.com.br>
Sent: Wednesday, September 10, 2025 11:11 AM
To: Stephen Colebourne <scolebourne at joda.org>
Cc: valhalla-dev <valhalla-dev at openjdk.java.net>
Subject: Re: Method names for Valhalla value types

Em qua., 10 de set. de 2025 às 11:54, Stephen Colebourne <scolebourne at joda.org<mailto:scolebourne at joda.org>> escreveu:

1) Basic - add/subtract/multiply/divide/negate
Used by BigDecimal/BigInteger

To me, style 1 communicates "update" -- x.add(y) -- add y to x, update x by adding y.
It would confuse me if "add" did not update x.
Following Stepanov in "Elements of Programming", I think of this as "accumulator style".

For immutable data types, I think style 2 communicates "new value".
In my own arithmetic code, I use sum, difference, product, quotient and remainder; division produces a pair; inverse, half, twice or double etc.

--
Pedro Lamarão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20250910/e2748345/attachment-0001.htm>


More information about the valhalla-dev mailing list