On 2016-12-08 10:01, Ulf Zibis wrote:
Am 08.12.2016 um 09:28 schrieb Peter Levart:
On 12/07/2016 11:28 PM, Roger Riggs wrote:
AbstractStringBuilder:
I agree with Claes' comment suggesting that IAE for negative
lengths is a pain
and defining it to append 0 would be natural in many use cases.
OTOH, inserting a simple Math.max(n, 0) instead of n where n could
get negative would achieve the same without complicating the
expression too much. Java standard APIs have a tradition of being
explicit rather than having implicit hidden logic which surely
shortens many usecases, but makes them harder to read and understand
for casual readers not intimately familiar with such API. The logic
to treat negative lengths as 0 is implicit and not universally correct.
+1
If we would treat negative values as 0, we loose a chance, where
programmers could become aware about possible errors in the logic of
their program.
Right, the two of you have convinced me that some exceptional
explicitness is the better choice in this (and likely most) cases.
Thanks!
/Claes
-Ulf