> Would you really write a function find_prime_factors() that takes an input of type "integer" and an output of type "prime", that you have previously defined?
If the language allows me to and its an important semantic part of my program, then yes. The same way as I would create types for units that need conversion.
Unless I'm writing low level performance sensitive code, yes, I want to encode as much of my semantics as I can, so that I can catch mistakes and mismatches at compile time, make sure units get properly converted and whatnot.
> What's so special about the lower bound of the possible set of values?
Nothing, I would encode a range if I can. But many things don't have a knowable upper-bound but do have a lower bound at zero: you can't have a negative size (for most definitions of size), usually when you have a count of things you don't have negatives, you know that a dynamically sized array can never have an element index less than 0, but you may not know the upper bound.
Also, the language has limitations, so I have to work within them. I don't understand your objection for using what is available to make sure software is correct. Also, remember that many of the security bugs we've seen in recent years came about because of C not being great at enforcing constraints. Are you really suggesting not to even try?
> And this is a can of worms that I prefer not to open...
And yet many languages do and even C++20 is introducing ranges which kind of sort of fall into this space.
If the language allows me to and its an important semantic part of my program, then yes. The same way as I would create types for units that need conversion.
Unless I'm writing low level performance sensitive code, yes, I want to encode as much of my semantics as I can, so that I can catch mistakes and mismatches at compile time, make sure units get properly converted and whatnot.
> What's so special about the lower bound of the possible set of values?
Nothing, I would encode a range if I can. But many things don't have a knowable upper-bound but do have a lower bound at zero: you can't have a negative size (for most definitions of size), usually when you have a count of things you don't have negatives, you know that a dynamically sized array can never have an element index less than 0, but you may not know the upper bound.
Also, the language has limitations, so I have to work within them. I don't understand your objection for using what is available to make sure software is correct. Also, remember that many of the security bugs we've seen in recent years came about because of C not being great at enforcing constraints. Are you really suggesting not to even try?
> And this is a can of worms that I prefer not to open...
And yet many languages do and even C++20 is introducing ranges which kind of sort of fall into this space.