std.xml validity checking is absurd

Ali Çehreli acehreli at yahoo.com
Fri Feb 8 09:16:25 PST 2013


On 02/08/2013 08:18 AM, Dicebot wrote:
 > On Friday, 8 February 2013 at 16:11:14 UTC, Ali Çehreli wrote:
 >> As the module writer, I don't know whether my function is going to be
 >> used as an "API function" or as an "internal function" in somebody
 >> else's module.
 >
 > Then it is an API function, as far as I understand DbC, and should never
 > rely on contract to validate input.

It is an internal function if I use it so:

import std.math;
import std.exception;

void foo(double a, double b)
{
     enforce(a > b, "a must be greater than b");
     sqrt(a - b);
}

void main()
{}

See how sqrt() is *not* on my module's API? I have already enforced that 
my API function foo() is called correctly. My call to sqrt() is an 
internal call of my module. Therefore the checks inside sqrt() should 
not be repeated beyond my testing stage.

Ali



More information about the Digitalmars-d mailing list