Discussion Thread: DIP 1037--Add Unary Operator ...--Community Review Round 1

Paul Backus snarwin at gmail.com
Wed Oct 28 18:00:15 UTC 2020


On Wednesday, 28 October 2020 at 17:52:41 UTC, Ola Fosheim 
Grøstad wrote:
> On Wednesday, 28 October 2020 at 17:48:21 UTC, Paul Backus 
> wrote:
>> The library author could just as easily use `T.init` as the 
>> initial value, and if the code is never tested with floats, it 
>> will appear to work just fine. So requiring an initial value 
>> does nothing to prevent this hypothetical bug.
>
> No, it is common to fold with 0 for addition and 1 for 
> multiplication. Anyone that has some programming background 
> will use that when the think about initial value.

The bug you described in your previous post can only ever occur 
if the programmer uses an incorrect initial value, not if he or 
she forgets to include an initial value. If you are willing to 
assume that the programmer will not use an incorrect initial 
value, then the bug you are (supposedly) worried about will never 
occur in the first place.


More information about the Digitalmars-d mailing list