On 11/12/13 8:05 AM, Vladimir Panteleev wrote:
On Tuesday, 12 November 2013 at 15:56:25 UTC, Andrei Alexandrescu wrote:
I think NaNs are singular unordered values that make invalid inputs
for either sort or isSorted. We should simply add an assert to isSorted.
Considering their effect on the program state, NaNs can be seen as
invalid input, and asserts are not suitable for input validation.
I should know, since I dedicated a chapter to the topic in TDPL :o).
It's all a matter of boundaries, i.e. what you consider "input" and what
you consider "precondition". When user code reads floating point data
off of disk, they should do real validation. For isSorted we could say
that the output is only defined for inputs that are comparable. Or
indeed we could specify that isSorted throws if unordered data is
presented, and verify everything at runtime, at a cost in efficiency.
It's a judgment call, not a cut and dried decision. In this case I think
assert is the better call.
Andrei