19-Nov-2013 02:49, Walter Bright пишет:
On 11/18/2013 2:37 PM, Andrei Alexandrescu wrote:
On 11/18/13 1:50 PM, Walter Bright wrote:
I believe this is solving the problem in the wrong place. The function
being called should not be throwing, and should be defined as not
throwing. See my other posts in this thread on the topic.
I think a stance of unceremoniously halting the program upon passing
the wrong
parameters to a standard library function is a bit excessive.
Dang, I gotta argue this with you too? :-)
Forget the philosophical argument for the moment and let's try a
pragmatic one - code that doesn't check its arguments and doesn't throw
is going to inline better, run faster, and be smaller. To have a high
performance language, we have to have this.
This is why we have a -release switch: so we can run with or without
checking the arguments for bugs.
Input data validation is where exceptions come in. Those are relatively
rare compared with processing validated data, and so separating out the
slow data validation path from the validated high speed path makes
pragmatic sense.
Rejecting this approach throws (!) out the whole concept of contract
programming.
There is a whole class of functions where validation is ~ the same
amount of work as scrubbing the input. Do I need to provide an example
of parser? :)
--
Dmitry Olshansky