Checking function parameters in Phobos
Walter Bright
newshound2 at digitalmars.com
Wed Nov 20 16:26:59 PST 2013
On 11/20/2013 3:16 AM, Jonathan M Davis wrote:
> ValidatedString would then avoid any extra validation when iterating over the
> characters, though I don't know how much of an efficiency gain that would
> actually be given that much of the validation occurs naturally when decoding
> or using stride. It would have the downside that any function which
> specializes on strings would likely have to then specialize on ValidatedString
> as well. So, while I agree with the idea in concept, I'd propose that we
> benchmark the difference in decoding and striding without the checks and see if
> there actually is much difference. Because if there isn't, then I don't think
> that it's worth going to the trouble of adding something like ValidatedString.
Utf validation isn't the only form of validation for strings. You could, for
example, validate that the string doesn't contain SQL injection code, or
contains a correctly formatted date, or has a name that is guaranteed to be in
your employee database, or is a valid phone number, or is a correct email
address, etc.
Again, validation is not defined by D, it is defined by the constraints YOUR
PROGRAM puts on it.
More information about the Digitalmars-d
mailing list